Link to home
Start Free TrialLog in
Avatar of rock815
rock815

asked on

DataGrid / TemplateColumn / ItemCreated Event Question

Okay, I've been struggling to present my issue in terms people can understand, so here goes my best:

I have a DataGrid that has a list of paragraphs.  In the last column, a templatecolumn, I have a DropDownList for the Order in which the paragraphs are displayed.  The DropDownList is generated from the ItemCreated Event (unless you recommend a better way).

This all works fine.

The issue is getting the existing value of the OrderId from the Database and as the SelectedValue of the DropDownList.

Normally, I would do it similar to this:
dlOrder.Items.FindByValue(e.Item.Cells[5].Text).Selected=true;

But since e.Item.Cells[5].Text is a BoundColumn created in the Event process before this Column is created I cannot grab that value this way.

My question is what would be the best way to accomplish what I'm trying to do?

Thanks, in advance, for your help on the issue! :-)

Regards

The theory:
This is part of an admin module of a website.  The theory is that once the order of paragraphs is updated in each column with a value of 1-(MaxNoOfParagraphs) that you would click a button outside the datagrid that would be "Update Paragraph Order".  That would iterate through that collection of rows and update each row with the proper value for the OrderId.

Avatar of dlarlick
dlarlick


  I use the ItemDataBound event and the FindControl to obtain the dropdownlist within the cell.
  Rough example below, Make sure you have the  TestingDataGrid.ItemDataBound += {etc...} delegate setup.

private void TestingDataGrid_ItemDataBound(object sender, DataGridItemEventArgs e)
{
   int tempID;

   //Only perform processing for the rows of the grid,
   //**skip the header and footer records from processing**
   if (e.Item.ItemType == ListItemType.Item ||
    e.Item.ItemType == ListItemType.AlternatingItem)
    {            
          //Retrieve the status from the datagrid
          tempID= Convert.ToInt32(e.Item.Cells[5].Text);

         DropDownList tempDropDown;
         tempDropDown = (DropDownList) e.Item.Cells[--put your offset here--].FindControl("dlOrder");

         tempDropDown.Items.FindByValue(e.Item.Cells[5].Text).Selected=true;
     }
}
Avatar of rock815

ASKER

That's pretty much what I'm trying to accomplish using the ItemCreated event.  It has no problem rendering the drop down from there, but I cannot get it to grab the value of another column from the datagrid.  That is my issue entirely.

If I could figure out what Row of the Datagrid the current ItemCreated Event is in, that would theoretically solve everything....

Can you help there?
ASKER CERTIFIED SOLUTION
Avatar of dlarlick
dlarlick

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rock815

ASKER

Thank you for your help on this, using the right event solved everything!!! :-)