开发者

Repeat header row after each row dynamically

How can I repeat the header row after each row of grid开发者_如何学编程view?


You might add code to the rowdatabound-event of your grid:

protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        GridViewRow row = new GridViewRow(e.Row.RowIndex, 0, DataControlRowType.Header, DataControlRowState.Normal);

        TableCell cell = new TableCell();
        cell.Controls.Add(new Label { Text = "Header" }); //as needed

        row.Cells.Add(cell);

        Table tbl = (e.Row.Parent as Table);

        tbl.Controls.AddAt(e.Row.RowIndex * 2 + 1, row);            
    }
}

In this example, I have removed the gridview header altogether as you write your own in code behind.


You can't without re-writing the control render method. How about using a repeater and putting it in the item separator element too?


Well, it is way easier to either put the markup for the header also in the item template. Overriding the Render method for something like this is probably overkill.

But if there is a reason to do this, it is at least missing from your question.


If you need the header row markup in every single item row, why not just include the markup that is currently in your header into the ItemTemplate ...?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜