Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 12th, 2007, 11:15 PM
Registered User
 
Join Date: Jan 2007
Location: , , .
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
Reply With Quote
  #2 (permalink)  
Old January 13th, 2007, 12:30 PM
Friend of Wrox
 
Join Date: Apr 2004
Location: San Francisco, CA, USA.
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

Reply With Quote
  #3 (permalink)  
Old January 13th, 2007, 12:51 PM
Registered User
 
Join Date: Jan 2007
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

TY a ton .

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 02:00 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.