Binding a image button to a datagrid

H

herman

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
 
M

Michael Tkachev

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
}
}
 
H

herman

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 said:
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 said:
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
 
M

Michael Tkachev

Hi

string text = tb.Text;
:)

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

Michael
(e-mail address removed)


herman said:
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" <[email protected]> wrote in message
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 said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top