DataGrid with edititemtemplate

G

Guest

Hi
I have a datagrid defined which I would like to make it editable. So I put
in some editcommand and BoundColumn and template column with item template.
I don't have problem in setting a column to textbox in edititemtemplate, but
how do I set it to dropdownlist and how do I set the selectedIndex?

TIA

--
 
B

Brock Allen

You can handle the DataGrid's ItemDataBound event. The DataGridItemEventArgs
passed allows you to access the e.Item which is the row in the DataGrid.
Find the cell you want, then use FindControl("IDOfYourDDL") to get your DropDownList
in the Cell. Once you have that, you can do any custom work with it you need
to.
 
G

Guest

Do you mean I should use ItemDataBound event to bind data to the
dropdownlist control and disable it before the DataGrid got displayed, then
onEditCommand event, I simply enable the control?

TIA
 
B

Brock Allen

To change the Selected item in the DDL, you're going to have to get access
to the DDL. This can be accomplished by handling the ItemDataBound event
on the Grid. Oh, one other thing I should have mentioned is that since you're
only doing this when you edit the row, you should double check for e.Item.ItemType
== ListItemType.EditItem.

Oh, just rereading your original post, I think what you're going to want
is to put a EditItemTemplate. Inside of that put your own DDL. And then,
yes, in the ItemDataBound you can data bind the DDL to whatever list it needs
to be.
 
E

Eric

Hi, Brock.

I've spent the past 5 hours on this problem, trying to figure out how to
change the SelectedValue, something that should really only take 30 second.
I've stumped three other developers in my small office.

With your help I still can't quite get it.

I have a static list for the DDL but I need to change the SelectedValue to
the data that's being edited in the template column of the DataList. I'm not
inputting the list from a DataReader or anything.

The problem is I can't access or find the DDL control. I've got a hunch
that the control I want might not exist when I am trying to access it, since
it's built on-the-fly (template).

I've got a dl_EditCommand sub and a dl_ItemDataBound (I just added this one
as per your suggestion). When I click "Edit", ItemDataBound fires before the
EditCommand is fired. Is there a method that fires later than these two?

Help is much appreciated!
 

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,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top