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