Asp.Net数据网格列排序出错 [英] Error in Asp.Net data grid column sort

查看:81
本文介绍了Asp.Net数据网格列排序出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个包含5列的网格设计,如

< asp:BoundField DataField =COUNTRY_NAMEHeaderText =国家/地区名称SortExpression =COUNTRY_NAME/>



i我尝试在用户点击排序事件的列标题时添加排序图标。



int i = 0;

foreach(GridView.Columns中的DataGridColumn col)

{

if(col.SortExpression == e.SortExpression)

CustomersGridView.Columns [i] .HeaderStyle.CssClass =gridHeaderSort;

i ++; <在获取错误时,




无法转换类型为'System.Web.UI的对象.WebControls.BoundField'键入'System.Web.UI.WebControls.DataGridColumn'。





请帮助。



问候,Kiruba

Hi,

I have a web grid with 5 columns designed like
<asp:BoundField DataField="COUNTRY_NAME" HeaderText="Country Name" SortExpression="COUNTRY_NAME" />

i am trying to add sort icons whenever user clicks on column header on sorting event.

int i =0;
foreach (DataGridColumn col in GridView.Columns)
{
if (col.SortExpression == e.SortExpression)
CustomersGridView.Columns[i].HeaderStyle.CssClass = "gridHeaderSort";
i++;
}

while doing am getting error :
Unable to cast object of type 'System.Web.UI.WebControls.BoundField' to type 'System.Web.UI.WebControls.DataGridColumn'.


Please Help.

Regards, Kiruba

推荐答案

你正在使用 DataGrid 控件 [< a href =http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datagrid%28v=vs.110%29.aspxtarget =_ blanktitle =新窗口> ^ ],使用BoundColumn [ ^ ]而不是 BoundField [ ^ ]。



如果你想继续使用 DataGrid 类,你需要替换< asp:BoundField ... /> with < BoundColumn ...> 。或者,您可以切换到使用较新的 GridView 控制 [ ^ ]而不是。
You're using the DataGrid control[^], which uses BoundColumn[^] instead of BoundField[^].

If you want to continue using the DataGrid class, you'll need to replace <asp:BoundField .../> with <BoundColumn ...>. Alternatively, you could switch to using the newer GridView control[^] instead.


这篇关于Asp.Net数据网格列排序出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆