zoukankan      html  css  js  c++  java
  • GridView中绑定DropDownList并用DropDownList显示对应字段数据;

    1. HeaderTemplateRowDataBound设置GirdView 的 DataKeyNames="Name" 即数据源中的字段,我设置的是:Name; 
    2. 添加GridView事件:
      RowDataBound 
    3. 在事件事首先判断行的类型是不是数据行;因为第一行通常是 
      HeaderTemplate;(图中的第一行就是表头,如编号,标识码,商品名称。。。。)
    4. 在当前行中查换DropDownList的Id;DropDownList ddlInType = e.Row.FindControl("ddlInType"as DropDownList; 

      设置DropDownList的数据源及绑定的字段;

      然后再取出当数据库中的值,与DataKeys绑定;(上面提到的 DataKeyNames="Name")

     

        

           

    protected void gvInBillList_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                
    if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    DropDownList ddlInType 
    = e.Row.FindControl("ddlInType"as DropDownList;
                    ddlInType.DataSource 
    = new InBillManager().GetDropDownList();
                    ddlInType.DataValueField 
    = "Id";
                    ddlInType.DataTextField 
    = "Name";
                    ddlInType.DataBind();

                    
    this.SelectDropDownList(ddlInType, this.gvInBillList.DataKeys[e.Row.RowIndex]["Name"].ToString());
                }

            }

          

    public void SelectDropDownList(DropDownList objDropDownList, string valueOrText)
            {
                objDropDownList.ClearSelection();

                ListItem objLI 
    = objDropDownList.Items.FindByValue(valueOrText);

                
    if (objLI == null)
                {
                    objLI 
    = objDropDownList.Items.FindByText(valueOrText);
                }

                
    if (objLI != null)
                {
                    objDropDownList.ClearSelection();

                    objLI.Selected 
    = true;
                }

           }

            


  • 相关阅读:
    dinoql 试用
    dinoql 使用graphql 语法查询javascript objects
    使用git_stats 统计分析git 仓库代码&& 集成webhook
    使用gitstats分析git 仓库代码
    PostGraphile 4.4 发布,支持real time 查询
    cube.js 学习(十)cube 来自官方的学习网站
    Optimize Cube.js Performance with Pre-Aggregations
    cube.js 学习(九)cube 的pre-aggregation
    cube.js 学习(八)backend部署模式
    cube.js 学习(七)cube.js type 以及format 说明
  • 原文地址:https://www.cnblogs.com/zhuiyi/p/2048326.html
Copyright © 2011-2022 走看看