Groups | Blog | Home
all groups > asp.net datagrid control > october 2004 >

asp.net datagrid control : Binding a image button to a datagrid


c24chan NO[at]SPAM gmail.com
10/5/2004 7:42:36 PM
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?

Michael Tkachev
10/6/2004 3:14:02 PM
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
}
}


[quoted text, click to view]

c24chan NO[at]SPAM gmail.com
10/7/2004 6:42:47 AM
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?

[quoted text, click to view]
Michael Tkachev
10/8/2004 1:05:29 PM
Hi

string text = tb.Text;
:)

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

Michael
m_tkachev@hotmail.com


[quoted text, click to view]

AddThis Social Bookmark Button