Template Column

V

VJ

Hi...

This should be simple I guess.. I have a dropdownbox as a template column in
my datagrid. When the selected item changes in this dropdown item, I need to
know the corresponding datarow in the datagrid. How do I determine this?

VJ
 
T

Teemu Keiski

If you handle DDL's SelectedIndexChanged event, you get the DDL instance
itself from the first parameter of event handler method. Ok, in the control
hierarchy DDL is inside a TableCell which is inside a DataGridItem (which
actually inherits from TableRow). Ok, so answer is that you cast the sender
event argument to DDL and get its parent's parent control something like:

DataGridItem item=(DataGridItem)((DropDownList)sender).Parent.Parent;

or straight with NamingContainer property:

DataGridItem item=(DataGridItem)((DropDownList)sender).NamingContainer;

The trick here is that DataGridItem can return the index of the DataGridItem
in Items collection of DataGrid (or DataItem itself if you are databinding)
which you can use to access the correct data source row. If you are not
databinding as you probably are not when this is run, you need to somehow
refetch the data.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke

Hi...

This should be simple I guess.. I have a dropdownbox as a template column in
my datagrid. When the selected item changes in this dropdown item, I need to
know the corresponding datarow in the datagrid. How do I determine this?

VJ
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top