Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 12th, 2007, 11:15 PM
Registered User
 
Join Date: Jan 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default TextBox inside GridView

Hi I am really a beginner in ASP.NET so I am sorry for possible stupid question.
I have GridView on the form, inside GridView I have a textBox, I am trying to get textBox.text and for some reason I am getting empty string. Here is the code example:

.aspx Page

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" EnableEventValidation="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
<asp:GridView runat="server"
                ID="test1"
                AutoGenerateColumns="false"
                Visible="true"
                AllowPaging="true"
                DataKeyNames="CompanyName"
                ShowHeader="false"
                ShowFooter="false">
    <EmptyDataRowStyle BackColor="AliceBlue" />
    <Columns >
    <asp:BoundField DataField="CompanyName" ItemStyle-Width="200" />
    <asp:TemplateField ItemStyle-Width="200" Visible="true" >
        <ItemTemplate >
            <asp:TextBox runat="server" id="txt1" Rows="3">
            </asp:TextBox>
        </ItemTemplate >
    </asp:TemplateField>
    </Columns>
    </asp:GridView>
    <br />
    <br />
    <asp:Button runat="server" ID="btText" />
    </div>
    </form>
</body>
</html>

.aspx.vb page

Imports System.Data
Imports System.Data.SqlClient
Partial Class _Default
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim connection As SqlConnection = New SqlConnection("Persist Security Info=False;Integrated Security=true;Initial Catalog=Northwind;server=(local)")
        Dim adapter As SqlDataAdapter = New SqlDataAdapter("SELECT CustomerID,CompanyName,Address from Customers", connection)
        Dim table As DataTable = New DataTable("Table")
        Dim dataSet As DataSet = New DataSet("dataSet")
        adapter.Fill(table)
        Dim dv As DataView = table.DefaultView
        test1.DataSource = dv
        test1.DataBind()
    End Sub
    Protected Sub test1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles test1.PageIndexChanging
        test1.PageIndex = e.NewPageIndex
        test1.DataBind()
    End Sub
Protected Sub btText_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btText.Click
        For Each curRow As GridViewRow In test1.Rows
            Dim strR As String = CType(curRow.FindControl("txt1"), TextBox).Text
            Response.Write("TEST : " & strR & "<br>")
        Next
    End Sub

End Class
 
Old January 13th, 2007, 12:30 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Stick the whole chunk of logic where you populate the dataset and bind the GridView to it inside an

Code:
If IsPostBack=False then
     'Code to populate dataset and bind to GridView here
End If
...and you should be in business.

Aaron

 
Old January 13th, 2007, 12:51 PM
Registered User
 
Join Date: Jan 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

TY a ton .






Similar Threads
Thread Thread Starter Forum Replies Last Post
Change Text of Textbox inside Template DarkForce ASP.NET 2.0 Basics 3 September 14th, 2012 07:11 AM
Two DropDownList Inside a Gridview ilayaraja ASP.NET 3.5 Basics 3 December 5th, 2008 06:26 PM
get value of textbox inside datagrid khaink ASP.NET 1.0 and 1.1 Basics 9 October 2nd, 2007 10:05 AM
DropDownList inside a GridView aidoco ASP.NET 2.0 Basics 0 October 13th, 2006 04:24 AM
Use Response object inside asp:textbox tag fizzerchris ASP.NET 1.0 and 1.1 Basics 0 August 22nd, 2006 07:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.