.NET Questions (CLOSED)

Questions and Answers on any aspect of .NET. Now closed.

This discussion group is now closed.

Have a question about .NET development? Try stackoverflow.com, a worldwide community of great developers asking and answering questions 24 hours a day.

The archives of .NET Questions contain years of Q&A. Even older .NET Questions are still online, too.

Datagrid Header from ItemDataBound...

I *think* I am just being dense here...

Anyway I have a rather complex datagrid, with variable numbers of columns based on the data it receives from an uploaded excel file. and a couple of fixed columns specified in the <asp:datagrid... bit.

The header for the imported columns is a programmatically generated template with a couple of labels in, and a checkbox.

As I bind the datagrid, I do some logic to see if things are in a database already, and maybe some other checks.

Having found a control in a cell I want to work back to the header of the column that the control is in, so I can do some stuff (based on the cells contents)

The real code(tm) is a bit funky to get the ID of the correct column so I have psudoed the code a bit. The findcontrol works okay.

Protected Sub dgTests_ItemDataBound(ByVal .....
 If e.Item.ItemType = ListItemType.Item Then
Dim lblResultName As Label = CType(e.Item.FindControl("lblTestName" & item), Label)

'From lblTestName, work back to the header and .findcontrol("TestID") to get which test the result is from.
 end if
end sub

Writing this out makes me think maybe I am better doing all the binding, then work back through the bound datagrid...

Is there a real "best way" to do this kind of stuff?

I have never done anything with variable numbers of columns before and it seems overly complex to me!

Any ideas or calls for more info accepted!
Friday, November 09, 2007
You can check the ListItemType to see if it is a Header row, or footer, or normal row, etc.

But the header row is not created in ItemDataBound you have to manipulte the header in the DataGrid's ItemCreated event.
Red Stater
Friday, November 09, 2007

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz