Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i want to create a sub header in gridview first header is worked fine. but for second header i used row created event. but this is no working properly. any one guide me about how to enter Text box on every column in second header for filter data.
Thanks in advance
my code is below.
[Wajid Khaksar]

What I have tried:

this is for first header in aspx
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowCreated="GridView1_RowCreated">







and for second is c# code but it is not working plz help me about

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType==DataControlRowType.DataRow)
{




GridViewRow HeaderGridRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);



TableCell HeaderCell = new TableCell();
HeaderCell.Text = "Filter Record";
TextBox tb = new TextBox();
e.Row.Cells[0].Add(tb);
HeaderCell.ColumnSpan = 1;
HeaderGridRow.Cells.Add(HeaderCell);
GridView1.Controls[0].Controls.AddAt(0, HeaderGridRow);
//and similar way for mor cells
}
}
Posted
Updated 23-Sep-16 1:12am

1 solution

You need to check for Header RowType instead of DataRow so your code will be added to the header. Have you tried debugging your code?

C#
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
	if(e.Row.RowType == DataControlRowType.Header)
	{
		//your code here for adding the TextBox to the Header

	}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900