I am merging 2 rows in the column header of a Gridview. The row has to sort. To add the sorting ability to the column header I need to add the LinkButton control to the TableCell and then assign the Sorting method to the click event. I am getting the 'No overload for SectionGridView_Sorting...' I don't know how to add the event the the click action. This is the code:
TableCell cellSecID = new TableHeaderCell();
cellSecID.HorizontalAlign = HorizontalAlign.Center;
cellSecID.RowSpan = 2;
LinkButton lnkHeader = new LinkButton();
lnkHeader.PostBackUrl = HttpContext.Current.Request.Url.LocalPath;
lnkHeader.CommandArgument = "SectionID";
lnkHeader.Text = "SectionID";
lnkHeader.Click += new EventHandler(SectionGridView_Sorting); //This is the problem
cellSecID.Controls.Add(lnkHeader);
How to assign the Sorting method to the click event?
UPDATE This is my Sorting Method:
protected void SectionGridView_Sorting(object sender, GridViewSortEventArgs e)
{
//Get the CourseID
populateSectionGrid();
DataTable dtSectionGridData = SectionGridView.DataSource as DataTable;
SectionGridViewSortExpression = e.SortExpression;
if (dtSectionGridData != null)
{
DataView dataView = new DataView(dtSectionGridData);
dataView.Sort = SectionGridViewSortExpression + " " + ConvertSectionSortDirectionToSql(e.SortDirection);
SectionGridView.DataSource = dataView;
SectionGridView.DataBind();
}
}
After UPDATE in the question there is workaround for your issue:
Change this line:
In the event handler:
In the gridview sorting event:
NOTE: above code is not tested. Minor tweaks for refinements may be required. Like keeping
SortExpression
andSortDirection
and checking in thegridview sorting
event. in