Click here to Skip to main content
16,022,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have to add textbox on top row inside the grid. and when end user insert the search value than grid result should be populated accordingly.

But how i can add text box only on top row. CSS of grid does not allow me to add text boxes on header. my grid should look like this

Header: Emp# EmpName EmpAddd
Search TextBox : [_____] [_____] [______]
Lable show data : 1 aaa adress1
Lable show data : 2 bbb adress2
Lable show data : 3 ccc adress3

Search is not my problem but how i can add text box only for top row in grid view. I can not add always text box and give the look n feel of other text box as label.
Posted

The server side code is follows:

protected void GVtest_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//Create the Row
GridViewRow row = new GridViewRow(-1, -1, DataControlRowType.DataRow, DataControlRowState.Normal);
//Add the two Columns
if(e.Row.RowIndex == 1)
row.Cells.AddRange(CreateSarchPanel());
//get a reference to the table that holds this row
Table gridviweTable = (e.Row.Parent as Table);
//Add the row at 0 indx.
gridviweTable.Rows.AddAt(0, row);
}

}
private TableCell[] CreateSarchPanel()
{
TableCell[] cells = new TableCell[2];
TableCell cell;
TextBox tb = new TextBox();
tb.ID = "TextBoxSearchCriteria1";
//The first column
cell = new TableCell();
tb = new TextBox();
cell.Controls.Add(tb);
cells[0] = cell;
//The second column
cell = new TableCell();
TextBox tb2 = new TextBox();
tb2.ID = "TextBoxSearchCriteria2";
cell.Controls.Add(tb2);
cells[1] = cell;
return cells;
}
 
Share this answer
 
v2
I solved it and explain the logic in my blog

http://helpondesk.blogspot.com/2011/04/search-panel-inside-grid.html[^]

Latter i will add sample code also.
 
Share this answer
 
Many ASP.NET server controls have "Convert to template" smart tag function. Investigate this possibility. And also it seems there is HeaderTemplate tag available in markup mode which allows to create custom template too.
 
Share this answer
 
v2

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