Professional Web Applications Themes

Binding a image button to a datagrid - ASP.NET Data Grid Control

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

  1. #1

    Default Binding a image button to a datagrid

    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 Guest

  2. #2

    Default Re: Binding a image button to a datagrid

    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" <c24chan> wrote in message
    news:5c8a87e8.0410051842.d881e3eposting.google.co m...
    > 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 Guest

  3. #3

    Default Re: Binding a image button to a datagrid

    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" <m_tkachevhotmail.com> wrote in message news:<ehx35V5qEHA.2816TK2MSFTNGP10.phx.gbl>...
    > 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" <c24chan> wrote in message
    > news:5c8a87e8.0410051842.d881e3eposting.google.co m...
    > > 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 Guest

  4. #4

    Default Re: Binding a image button to a datagrid

    Hi

    string text = tb.Text;
    :)

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

    Michael
    [email]m_tkachevhotmail.com[/email]


    "herman" <c24chan> wrote in message
    news:5c8a87e8.0410070542.133234c6posting.google.c om...
    > 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" <m_tkachevhotmail.com> wrote in message
    news:<ehx35V5qEHA.2816TK2MSFTNGP10.phx.gbl>...
    > > 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" <c24chan> wrote in message
    > > news:5c8a87e8.0410051842.d881e3eposting.google.co m...
    > > > 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 Guest

Similar Threads

  1. Replies: 2
    Last Post: April 29th, 05:16 PM
  2. Binding a Radio Button Group to a Data Holder
    By SecondBridge in forum Macromedia Flash Actionscript
    Replies: 0
    Last Post: February 13th, 05:04 PM
  3. DataGrid Cell with Image Button In It
    By KJ in forum ASP.NET Data Grid Control
    Replies: 2
    Last Post: December 16th, 02:55 PM
  4. Adding image button to a datagrid in execution time
    By Andrés Giraldo in forum ASP.NET Building Controls
    Replies: 0
    Last Post: September 18th, 05:12 PM
  5. Image Button in Datagrid WebControl
    By Alvin Bruney in forum ASP.NET Data Grid Control
    Replies: 7
    Last Post: August 23rd, 04:33 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139