zoukankan      html  css  js  c++  java
  • 【ASP.NET】GridView中的技巧收集

    1.列表中数字变字符的简易方法

    我们在程序中需要对列表控件Datagrid、Gridview等进行绑定时,有时需要将具体特定含义的数字变成字符,我将自己处理的一种方式贴出来做个记录。

    原理:通过增加新的一列,根据数字列的关系,在新列中赋字符或者汉字。然后绑定新列。

    代码:

    前台:
    <asp:BoundField DataField="statueName" HeaderText="报表状态" SortExpression="statueName">
      <itemstyle horizontalalign="center" />
    </asp:BoundField>
    后台:
     #region 绑定列表事件
            protected void BindData1()
            {
                string where = "";

                if (!string.IsNullOrEmpty(txtEnterpriseName.Text.Trim()))
                {
                    where += " and a.Enterprise_Code like '%" + txtEnterpriseName.Text.Trim() + "%' or a.EnterpriseName like '%" + txtEnterpriseName.Text.Trim() + "%' ";
                }
                DataSet ds = DalHelper.MonthlyEnterpriseMonitor.GetList(where);
                ds.Tables[0].Columns.Add("statueName",typeof(String));
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    switch (ds.Tables[0].Rows[i]["Status"].ToString())
                    {
                        //1 已报未审
                        case "1":
                            ds.Tables[0].Rows[i]["statueName"] = "已报未审";
                            break;
                        //2 已报打回
                        case "2":
                            ds.Tables[0].Rows[i]["statueName"] = "已报打回";
                            break;
                        //3.修改重报
                        case "3":
                            ds.Tables[0].Rows[i]["statueName"] = "修改重报";
                            break;
                        //4.已报通过
                        case "4":
                            ds.Tables[0].Rows[i]["statueName"] = "已报通过";
                            break;
                    }
                }
                this.gridView.DataSetSource = ds;
                this.gridView.DataBind();
            }
            #endregion

    2.前台调用后台的方法,并将前台参数带入

    前台:

    <asp:TemplateField HeaderText="操作" ShowHeader="False">
         <itemtemplate>
    <a href="#" style="display: <%# GetStatus(Eval("statueName"))%> "><img border="0" alt="" height="15" src="../images/houtai_42.gif" width="16" /></a>
    </itemtemplate>
    </asp:TemplateField>

    后台:

     protected string GetStatus(object data)
     {
       string ReturnValue = "none";
      if (data != null)
      {
        if (data.ToString() == "已报打回")
        {
          ReturnValue = "block";
        }
      }
       ReturnValue;
    }

    3.GridView不換行
    1.
    ItemsGrid.Attributes.Add("style", "word-break:keep-all;word-wrap:normal")

    2.
    在绑定数据的“编辑列”中将某列的HeaderStyle和ItemStyle的Wrap设为false.

  • 相关阅读:
    linux 系统管理(2) 文件或目录数量统计
    linux系统管理(1)之 内核编译选项查看
    apt 命令大全
    system命令
    ubuntu 登陆闪回
    网络知识之ipset
    mac 系统配置(一)
    windows下的qt编译器配置
    QT5.14.1+qwt-6.1.4编译
    无法打开源文件QtWidgets/QApplication
  • 原文地址:https://www.cnblogs.com/a311300/p/1388304.html
Copyright © 2011-2022 走看看