Custom header row in .NET datagrid?
April 17, 2008 1:39 PM   RSS feed for this thread Subscribe

How do I insert a row of identical drop-down lists into the top of my .NET datagrid?

I have a DataGrid whose source is an excel spreadsheet. My GUI needs to allow a user to select an option from a drop-down above each column. I'd like this row to be a part of the grid so that everything lines up all pretty-like.

The best option I've found is to manually create all the rows and columns and bind that to the grid. Another option was to use a repeater of datalists instead. Is there a simpler or better way? (I'm using C#)
posted by TimeTravelSpeed to computers & internet (5 comments total) 2 users marked this as a favorite
I should clarify that the loaded spreadsheet is different every single time. The solution needs to dynamically apply to spreadsheets of arbitrary size and with arbitrary column names.
posted by TimeTravelSpeed at 2:02 PM on April 17


You'll have to use a gridview for this, but it should work (adds a dropdown after the header row.)


protected void foo_DataBound1(object sender, EventArgs e)
{


GridViewRow row = new GridViewRow(0, 0, DataControlRowType.DataRow, DataControlRowState.Normal);
for (int i=0; i<2> {
DropDownList ddl = new DropDownList();
ddl.Items.Add("foo");
ddl.Items.Add("bar");
TableCell tc = new TableCell();
tc.Controls.Add(ddl);
row.Cells.Add(tc);
}

(sender as GridView).Controls[0].Controls.AddAt(1, row);


}

posted by sanko at 4:42 PM on April 17


 for (int i=0; i<2>  { 

should read
for (int i=0; i<2; i++) { // need to determine col. ct... Columns.Count returns 0

posted by sanko at 4:47 PM on April 17


Thanks sanko! I'll try that when I'm back at work.
posted by TimeTravelSpeed at 7:40 PM on April 17


Perfect sanko. Worked like a charm. Thank you very much!
posted by TimeTravelSpeed at 3:02 PM on April 21


« Older A childhood memory of two scie...   |   Is there software to automatic... Newer »

You are not logged in, either login or create an account to post comments



Related Questions
This question is so n00b that it hurts. February 17, 2008
How can I be cheap and have a good website? January 16, 2008
I need suggestions for getting over my CSS block March 27, 2007
Mark CF, if you're reading this, shoo! January 23, 2007
What web design language should I learn? December 5, 2006