Get textbox value from datagrid problem

Discussion in 'ASP .Net Datagrid Control' started by Steve F., Sep 2, 2004.

  1. Steve F.

    Steve F. Guest

    Hi, could you please tell me what is wrong with this piece of code.
    I have a DataGrid, and I would like to know the value of a textbox field,
    and it never returns anything.
    textbox is in item template.

    <asp:TemplateColumn HeaderText="Value">
    <ItemTemplate>
    <asp:TextBox id="txtInput" runat="server"></asp:TextBox>
    </ItemTemplate>
    </asp:TemplateColumn>

    Dim item As DataGridItem
    If Not IsPostBack Then

    For Each item In DataGrid1.Items
    Dim tb As TextBox = CType(item.FindControl("txtInput"),
    TextBox)
    ListBox1.Items.Add(tb.Text)
    Next
    End If


    Thank you.
    Steve
     
    Steve F., Sep 2, 2004
    #1
    1. Advertising

  2. Hi,

    the following code has been create in the C#. You will be able to translate
    to the VB.Net

    C#
    TextBox txt = ((TextBox)item.Columns[0].Controls[0]);

    VB:
    Dim tb As TextBox = CType(item.Columns(0).Controls(1))

    Right now you know how you can get a value from a textbox.

    bye


    "Steve F." <> wrote in message
    news:%...
    > Hi, could you please tell me what is wrong with this piece of code.
    > I have a DataGrid, and I would like to know the value of a textbox field,
    > and it never returns anything.
    > textbox is in item template.
    >
    > <asp:TemplateColumn HeaderText="Value">
    > <ItemTemplate>
    > <asp:TextBox id="txtInput" runat="server"></asp:TextBox>
    > </ItemTemplate>
    > </asp:TemplateColumn>
    >
    > Dim item As DataGridItem
    > If Not IsPostBack Then
    >
    > For Each item In DataGrid1.Items
    > Dim tb As TextBox = CType(item.FindControl("txtInput"),
    > TextBox)
    > ListBox1.Items.Add(tb.Text)
    > Next
    > End If
    >
    >
    > Thank you.
    > Steve
    >
    >
     
    Michael Tkachev, Sep 15, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. moid
    Replies:
    1
    Views:
    457
    nfedin
    Jan 27, 2004
  2. rockdale
    Replies:
    2
    Views:
    27,999
    rockdale
    Jun 6, 2006
  3. AGSHAR
    Replies:
    1
    Views:
    600
    AGSHAR
    May 31, 2008
  4. ErwinP
    Replies:
    1
    Views:
    783
    ErwinP
    Aug 19, 2005
  5. Steve
    Replies:
    4
    Views:
    233
    Steve
    Feb 7, 2006
Loading...

Share This Page