 |
|
 |
Instead of putting simple text, you have to put LinkButton control.
Something like this:
LinkButton lb = new LinkButton();
lb.ID = "LinkButtonSortHeader1";
lb.Text = "Department";
lb.OnClickClient="__doPostBack('ctl00$Sort$LinkButtonSortHeader1',''); return false;"
//Add Department
oTableCell.Controls.Add(lb);
oTableCell.ColumnSpan = 2;
oGridViewRow.Cells.Add(oTableCell);
Hope this would help you!
Thanks!
Rajendran Thiagarajan.
|
|
|
|
 |
|
 |
Thanks, I did it the same way:
Just one change:
LinkButton Ltitle = new LinkButton();
Ltitle.Text = "Project Title";
Ltitle.Click +=new EventHandler(LinkTitle_Click);
titleCell.Width = 220;
titleCell.Controls.Add(Ltitle);
//than just mapped it to GridView Sorting
protected void LinkTitle_Click(object sender, EventArgs e)
{
//Default gridView Sorting function
gridView_Sorting(this, new GridViewSortEventArgs("ProjectName", SortDirection.Ascending));
}
Amit
|
|
|
|
 |
|
 |
Hi Thanks for your code but I would like to have a header with data form the database... How would you do that ???
|
|
|
|
 |
|
 |
I didn't get you., Can you explain this in detail?
Thanks!
Rajendran Thiagarajan
|
|
|
|
 |
|
 |
You wrote 'department' and 'employee' but if I have a gridview which takes in params the state of the employee and in the header I want the state's name. ex:
SELECT * FROM employee WHERE statecode = params
| Header State Name (from database) |
Employee Name | Employee Mail | Employee tel. |
... | | |
Something like that, is that clear ?
|
|
|
|
 |
|
 |
That params mught be coming from a user unput, probably a dropdownlist. So instead of using "Department" for header text you can you someting like cboState.SelectedItem.Text
Noman Muhammad Aftab,
Software Mechanic
|
|
|
|
 |
|
 |
Your solution works fine.
The only change would really help if you have the pager activated for the top and bottom.
oGridView.Controls(0).Controls.AddAt(1, oGridViewRow)
Just changing this line would help and the header will not then float over the top of the Pager .
|
|
|
|
 |
|
 |
I searched all over the internet for this.
This works great. Thank you for your article.
|
|
|
|
 |
|
 |
Thanks for nice article. This is what I've been looking for. However, I still have problem with header text alignment. No matter what I do, I get the text aligned left in IE. But in firefox, it is working just fine and shown in the center.
|
|
|
|
 |
|
 |
Thanks. I got it working now. It was the style sheet in CSS file which was overriding the setting.
Thanks for the great article.
|
|
|
|
 |
|
 |
It was my fault.
It does work properly.
Thanks!!!
|
|
|
|
 |
|
 |
' Unable to cast object of type 'System.Web.UI.WebControls.GridViewRow' to type 'System.Web.UI.WebControls.Table'.
**This occured while trying to merge headers
We are trying it out in asp.net.
|
|
|
|
 |
|
 |
Cast is not possible, because gridviewrow represents ROW and Webcontrol.Table represents TABLE.
May I know what you are trying to do?
Thanks!
Rajendran Thiagarajan.
|
|
|
|
 |
|
 |
If I wanted to start in the 2nd cell of the table object instead of the first. How would I do that?
|
|
|
|
 |
|
 |
I didn't understand clearly that, what you are trying to do?
But as far as my understanding, you want to create object in second cell and leave the first cell as empty. To achieve this you have to create one empty cell and add it to Gridview row[Example: oGridViewRow.Cells.Add(oEmptyCell);] and you have to reduce one ColumnSpan value.
Sample Code:
if (e.Row.RowType == DataControlRowType.Header)
{
//Build custom header.
GridView oGridView = (GridView)sender;
GridViewRow oGridViewRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
//Empty Cell
TableCell oEmptyCell = new TableCell();
oEmptyCell.Text = " ";
oGridViewRow.Cells.Add(oEmptyCell);
TableCell oTableCell = new TableCell();
//Add Department
oTableCell.Text = "Department";
oTableCell.ColumnSpan = 2;
oGridViewRow.Cells.Add(oTableCell);
//Add Employee
oTableCell = new TableCell();
oTableCell.Text = "Employee";
oTableCell.ColumnSpan = 2;
oGridViewRow.Cells.Add(oTableCell);
oGridView.Controls[0].Controls.AddAt(0, oGridViewRow);
}
Thanks!
Thiagarajan Rajendran
.Net Developer
|
|
|
|
 |
|
 |
oTableCell.Text = "";
oTableCell.ColumnSpan = 1;
oGridViewRow.Cells.Add(oTableCell);
|
|
|
|
 |
|
 |
1. I download the code and run it, it complaint below code,
GridView oGridView = (GidView)sender;
Unable to cast object of type 'System.Web.UI.WebControls.GridView' to type 'GridView'.
2.Then I change to use
GridView gv = (System.Web.UI.WebControls.GridView')sender;
I get
Cannot implicitly convert type 'System.Web.UI.WebControls.GridView' to 'GridView'
Thanks
aaa
|
|
|
|
 |
|
 |
Your to the point artical was exactly what it needed. No Frills, just the answer!
I really do owe you one for that!
KES
Share the knowledge.
I can use all the help I can get and so do YOU!
KES
|
|
|
|
 |
|
 |
Hi,
Thats for the usefull article. I was hoping if there is a way to put usercontrol inside the newly created header cells. That would be a great help.
Thanks,
Alomgir
|
|
|
|
 |
|
 |
Is there a way to do the same thing to datagridview for windows development?
Thanks.
Jason Law
|
|
|
|
 |
|
 |
Yes, There should be possibility to do the same in windows datagridview. But I didn't get a chance to explore.
Thanks,
Thiagarajan Rajendran.
|
|
|
|
 |
|
 |
Thank you very much Rajendran Thiagarajan. great job. Your article is exactly what I was searching since two days.
-Vikram(vgehlot@hotmail.com)
|
|
|
|
 |
|
 |
When I merge headers as described in this article I get problem when updating the row using gridview's built in update command. if focuses me to wrong row.
Do you know how to fix this problem.
|
|
|
|
 |
|
 |
May I know what kind of problem you are facing(Need exact exception/error)?
Thanks!
Thiagarajan Rajendran
|
|
|
|
 |
|
 |
When updating the row with gridview's bult-in update command the wrong row was updated because there were 2 rows in header.
I have solved the problem when I put the code in Data_Bound event instead of Row_data_bound and now everything works fine.
|
|
|
|
 |