【发布时间】:2014-05-22 05:50:17
【问题描述】:
我正在合并 Gridview 的列标题中的 2 行。该行必须排序。要将排序功能添加到列标题,我需要将 LinkButton 控件添加到 TableCell,然后将 Sorting 方法分配给单击事件。我收到“SectionGridView_Sorting 没有过载...”我不知道如何将事件添加到单击操作中。这是代码:
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);
如何将Sorting方法分配给点击事件?
更新 这是我的排序方法:
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();
}
}
【问题讨论】:
-
看来你正在绑定链接按钮点击事件和已经存在的 gridview_sorting 事件。
-
你的
SectionGridView_Sorting实现EventHandlerdelegate?
标签: c# gridview merge row gridview-sorting