views:

499

answers:

2

Hey guys,

I've browsed what SO gives me as possible answers but I can't find a solution to my problem.

I have a gridview which should allow rows to be in edit mode. this more or less cancels out the use of a repeater I think.

The thing is, the header is "special". It should have multiple rows with some cells spanning multiple columns. an example:

| availabilty monitoring | monitoring |

| colu 1 | colu 2 | colu 3 | col 4 | col 5 |

(1 2 and 3 are parts of availabilty, 4 and 5 of usual monitoring)

keeping in mind that there's 4 rows in the header I have in mind.

is there any way to achieve this kind of header with the option to allow editing?

thx

+1  A: 

If you're using ASP.NET 3.5 you may want to have a look at the new ListView control. It combines the functionalities of a GridView with the functionalities of a Repeater or DataList.

http://msdn.microsoft.com/en-us/library/bb398790.aspx

Littlefool
A: 

First make the columns that you are going to have controls in into templated columns. Then you can have anything you want in there - a Table, TextBoxes, CheckBoxes, etc.

<HeaderTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text=''></asp:TextBox>
<asp:CheckBox ID="CheckBox1" runat="server" />
</HeaderTemplate>

You then have further control in the RowDataBound event:

protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    if (e.Row.RowType != DataControlRowType.Header)
         return;

    // let the third column span over the next 2 columns.
    e.Row.Cells[2].ColumnSpan = 3;
    e.Row.Cells[3].Visible = false;
    e.Row.Cells[4].Visible = false;

    // could span more than 1 row.
    e.Row.Cells[2].RowSpan = 2;

etc...

Together you have total control over your header section.

JBrooks