Binding a image button to a datagrid

Discussion in 'ASP .Net Datagrid Control' started by herman, Oct 6, 2004.

  1. herman

    herman Guest

    Hi:

    I have a datagrid and I've created a itemtemplate column with textbox
    inside each row like the following:

    <asp:TemplateColumn HeaderText="New NIBS DS1s">
    <ItemTemplate>
    <asp:TextBox ID="txtNewNIBSDS1" Runat="server" MaxLength="10"
    Enabled="True" Visible="True" Width="200" ReadOnly="False"
    Text=""></asp:TextBox>
    </ItemTemplate>
    </asp:TemplateColumn>

    However, when I goto the onclick event of that image button, I can't
    read the text of the textbox. I read somewhere that I need to give
    the image button a itemcommand, and make it bind to the datagrid so
    that I can read the datagrid's data, how can I do that?

    Thanks
     
    herman, Oct 6, 2004
    #1
    1. Advertising

  2. foreach(DataGridItem di in DataGrid.Items)
    {
    if(di.ItemType == ListItemType.AlternatingItem || di.ItemType ==
    ListItemType.Item)
    {
    TextBox tb = (TextBox)di.Cells[0].Controls[0];
    //your code
    }
    }


    "herman" <> wrote in message
    news:...
    > Hi:
    >
    > I have a datagrid and I've created a itemtemplate column with textbox
    > inside each row like the following:
    >
    > <asp:TemplateColumn HeaderText="New NIBS DS1s">
    > <ItemTemplate>
    > <asp:TextBox ID="txtNewNIBSDS1" Runat="server" MaxLength="10"
    > Enabled="True" Visible="True" Width="200" ReadOnly="False"
    > Text=""></asp:TextBox>
    > </ItemTemplate>
    > </asp:TemplateColumn>
    >
    > However, when I goto the onclick event of that image button, I can't
    > read the text of the textbox. I read somewhere that I need to give
    > the image button a itemcommand, and make it bind to the datagrid so
    > that I can read the datagrid's data, how can I do that?
    >
    > Thanks
     
    Michael Tkachev, Oct 6, 2004
    #2
    1. Advertising

  3. herman

    herman Guest

    Hi Michael:

    Thanks for your reply, however, when I am reading the text box value
    using your code, I get the same value as before. That is, I've the
    changed the value of the textbox from 0 to 1, but the value is still 0
    when I am reading it from the code, do you know why?

    "Michael Tkachev" <> wrote in message news:<>...
    > foreach(DataGridItem di in DataGrid.Items)
    > {
    > if(di.ItemType == ListItemType.AlternatingItem || di.ItemType ==
    > ListItemType.Item)
    > {
    > TextBox tb = (TextBox)di.Cells[0].Controls[0];
    > //your code
    > }
    > }
    >
    >
    > "herman" <> wrote in message
    > news:...
    > > Hi:
    > >
    > > I have a datagrid and I've created a itemtemplate column with textbox
    > > inside each row like the following:
    > >
    > > <asp:TemplateColumn HeaderText="New NIBS DS1s">
    > > <ItemTemplate>
    > > <asp:TextBox ID="txtNewNIBSDS1" Runat="server" MaxLength="10"
    > > Enabled="True" Visible="True" Width="200" ReadOnly="False"
    > > Text=""></asp:TextBox>
    > > </ItemTemplate>
    > > </asp:TemplateColumn>
    > >
    > > However, when I goto the onclick event of that image button, I can't
    > > read the text of the textbox. I read somewhere that I need to give
    > > the image button a itemcommand, and make it bind to the datagrid so
    > > that I can read the datagrid's data, how can I do that?
    > >
    > > Thanks
     
    herman, Oct 7, 2004
    #3
  4. Hi

    string text = tb.Text;
    :)

    try to send me your code. I will correct it. :

    Michael



    "herman" <> wrote in message
    news:...
    > Hi Michael:
    >
    > Thanks for your reply, however, when I am reading the text box value
    > using your code, I get the same value as before. That is, I've the
    > changed the value of the textbox from 0 to 1, but the value is still 0
    > when I am reading it from the code, do you know why?
    >
    > "Michael Tkachev" <> wrote in message

    news:<>...
    > > foreach(DataGridItem di in DataGrid.Items)
    > > {
    > > if(di.ItemType == ListItemType.AlternatingItem || di.ItemType ==
    > > ListItemType.Item)
    > > {
    > > TextBox tb = (TextBox)di.Cells[0].Controls[0];
    > > //your code
    > > }
    > > }
    > >
    > >
    > > "herman" <> wrote in message
    > > news:...
    > > > Hi:
    > > >
    > > > I have a datagrid and I've created a itemtemplate column with textbox
    > > > inside each row like the following:
    > > >
    > > > <asp:TemplateColumn HeaderText="New NIBS DS1s">
    > > > <ItemTemplate>
    > > > <asp:TextBox ID="txtNewNIBSDS1" Runat="server" MaxLength="10"
    > > > Enabled="True" Visible="True" Width="200" ReadOnly="False"
    > > > Text=""></asp:TextBox>
    > > > </ItemTemplate>
    > > > </asp:TemplateColumn>
    > > >
    > > > However, when I goto the onclick event of that image button, I can't
    > > > read the text of the textbox. I read somewhere that I need to give
    > > > the image button a itemcommand, and make it bind to the datagrid so
    > > > that I can read the datagrid's data, how can I do that?
    > > >
    > > > Thanks
     
    Michael Tkachev, Oct 8, 2004
    #4
    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. Jordan
    Replies:
    2
    Views:
    2,538
    Jordan
    Feb 10, 2004
  2. Amit
    Replies:
    6
    Views:
    13,809
    Assimalyst
    Oct 24, 2006
  3. pmclinn
    Replies:
    0
    Views:
    5,354
    pmclinn
    Jun 22, 2006
  4. Santosh
    Replies:
    0
    Views:
    1,863
    Santosh
    Aug 4, 2006
  5. Replies:
    2
    Views:
    866
    Kevin Grover
    Oct 20, 2006
Loading...

Share This Page