• 动态绑定ASPxGridView选中状态


    第一次写博文哈···

    这只是一个自己的方法笔记,用来从数据库读取数据,以绑定ASPxGridView的选择状态。

    代码
    private void SelectionState()
    {
    //根据条件从数据库读取数据,最后得到一个集合
    td_examtype et = new td_examtype();
    et.examtype_Profession
    = cbProfession.SelectedItem.Value.ToString();
    et.examtype_Type
    = Convert.ToInt32(cbType.SelectedItem.Value) + 1;
    et.examtype_Year
    = DateTime.Now.Year.ToString();
    List
    <td_examtype> list = Bll_examtype.GetExamType(et);
    //循环遍历ASPxGridView的行,匹配数据,如果成功,设置Selection,让这一行变成选中状态。
    for (int i = 0; i < ASPxGridView1.VisibleRowCount; i++)
    {
    DataRowView row
    = ASPxGridView1.GetRow(i) as DataRowView;
    if (list.Where(e => e.examtype_StudentCard == row[0].ToString()).SingleOrDefault() != null)
    {
    ASPxGridView1.Selection.SelectRow(i);
    }

    }
    }

    其中,ASPxGridView1.GetRow(i)得到的是一个对象,至于是什么对象,视你绑定的数据源而定,因为我绑定的是一个datatable,这里得到的就是datarowview,如果不知道要把它转换成什么对象,可以试试row.GetType().toString(),得到它的数据类型,然后转换就可以了。当然了,你也可以把绑定的数据源全部转换成datatable,这样就可以不用担心类型转换的问题了。另记得线清空ASPxGridView已有的选中状态,ASPxGridView1.Selection.UnselectAll();,再调用这个方法,不然每次更新的时候它只是清空了当前页的绑定状态哦。

    注:可能看不全的那个地方的代码是:if (list.Where(e => e.examtype_StudentCard == row[0].ToString()).SingleOrDefault() != null)

  • 相关阅读:
    [转载]oracle中的exists 和not exists 用法详解
    oracle中sql语句的优化(转帖)
    BizTalk Server 2010 使用 WCF Service [ 上篇 ]
    冒泡排序
    一起复习几何(4)
    手把手教你升级到 Mysql 5.5
    BizTalk Server 2010 映射器(Mapper) [ 上篇 ]
    基于OpenGL的渲染引擎
    BizTalk Server 2010 映射器(Mapper) [ 下篇 ]
    BizTalk Server 2010 映射器(Mapper) [ 中篇 ]
  • 原文地址:https://www.cnblogs.com/13142088/p/1946296.html
Copyright © 2020-2023  润新知