|
-
GridView and TextBox
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 textbox, I am trying to get text from text box and for some reason I am getting empty string. Here is the code example:
.aspx
<%@ 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
Similar Threads
-
By timmym in forum ASP.NET
Replies: 8
Last Post: 11-23-2008, 07:31 AM
-
By luvdairish in forum ASP.NET
Replies: 0
Last Post: 01-04-2007, 10:36 AM
-
By pgraves in forum ASP.NET
Replies: 0
Last Post: 08-30-2006, 09:58 AM
-
By calicojoe in forum ASP.NET
Replies: 1
Last Post: 08-08-2006, 05:02 PM
-
By clean in forum ASP.NET
Replies: 0
Last Post: 03-03-2006, 09:27 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks