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. Advertisements

  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. Advertisements

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:
    540
    nfedin
    Jan 27, 2004
  2. =?Utf-8?B?QW5hY2hvc3RpYw==?=

    RE: Textbox postback putting value,value

    =?Utf-8?B?QW5hY2hvc3RpYw==?=, Jun 18, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    787
    =?Utf-8?B?S2VpdGggRG9yYW4=?=
    Jun 21, 2004
  3. John Dalberg
    Replies:
    0
    Views:
    463
    John Dalberg
    Dec 20, 2005
  4. rockdale
    Replies:
    2
    Views:
    28,215
    rockdale
    Jun 6, 2006
  5. AGSHAR
    Replies:
    1
    Views:
    730
    AGSHAR
    May 31, 2008
  6. John Dalberg

    How to get key value in a master datagrid from a detail datagrid?

    John Dalberg, Dec 20, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    225
    John Dalberg
    Dec 20, 2005
  7. ErwinP
    Replies:
    1
    Views:
    1,131
    ErwinP
    Aug 19, 2005
  8. Steve
    Replies:
    4
    Views:
    426
    Steve
    Feb 7, 2006
Loading...