Groups | Blog | Home
all groups > asp.net > february 2005 >

asp.net : Help a newbie... (DataGrid bound & template columns)


David
2/6/2005 5:51:05 PM
Hello,

I have a DataGrid that has a template col with an asp:LinkButton tag in it.

When the LinkButton is clicked for this row, the onClick handler needs to do
some things with some various data items from this row and eventually modify
other data items in the same row before rebinding the whole thing.

But how do I get at the data fields in the "parent row" of the LinkButton
that was clicked? What is the syntax?

Thanks,

David



Roy
2/6/2005 7:11:43 PM
OMG. I'm actually posting an "answer" to this ng...not just a question.
:) It's a first.

Dave, firstly, you mention using a linkbutton... Why specificly?
Linking to another page seems to imply other things going on here...

Secondly, to find out how to gain access to various specific cells in a
datagrid, research "editing a datagrid," (there are a million sites
online about it) and look for the Sub where the page is updated. This
will teach you easily.

It's not involved. Something like "E.Item.Cells(6).Controls(0)"
references the 6th cell in the currently selected record.

Something like "Dim strXYZ As String = E.Item.Cells(6).Text" declares a
string variable and sets the cell's contents to it.
Vadivel Kumar
2/10/2005 9:17:43 AM
When you use Itemtemplate to bind a control
like any literal controls, you have to
get the handle of the control by using FindControl() like this,

LinkButton l = (LinkButton) e.Item.FindControl("LinkButtonID");

This will find the control and assign it to the object l, you can do any
kind of manipulation with the l and that
will be replicated to the actual control located in
the page.

Hope, this helps you.

Thanks & Regards
Vadivel Kumar
http:\\csharpblogs.blogspot.com

[quoted text, click to view]

AddThis Social Bookmark Button