Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Binding a image button to a datagrid

Reply
Thread Tools

Binding a image button to a datagrid

 
 
herman
Guest
Posts: n/a
 
      10-06-2004
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
 
Reply With Quote
 
 
 
 
Michael Tkachev
Guest
Posts: n/a
 
      10-06-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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



 
Reply With Quote
 
 
 
 
herman
Guest
Posts: n/a
 
      10-07-2004
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" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) 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

 
Reply With Quote
 
Michael Tkachev
Guest
Posts: n/a
 
      10-08-2004
Hi

string text = tb.Text;


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

Michael
http://www.velocityreviews.com/forums/(E-Mail Removed)


"herman" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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" <(E-Mail Removed)> wrote in message

news:<(E-Mail Removed)>...
> > 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" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed) 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView binding - how to stop initial binding Amit ASP .Net 6 10-24-2006 08:06 AM
pywin32 COM sort in Excel (late binding fails, early binding works) (+py2exe) kogrover@gmail.com Python 2 10-20-2006 04:08 PM
Binding data to datagrid header template on button click Santosh ASP .Net 0 08-04-2006 04:57 AM
Asp 1.1 Add Image to datagrid via datatable binding pmclinn ASP .Net 0 06-22-2006 07:23 PM
Data Binding - using inline code vs. functions vs. straight binding Jordan ASP .Net 2 02-10-2004 08:32 PM



Advertisments