zoukankan      html  css  js  c++  java
  • DataGrid应用技巧两则(downmoon)列求和与列字段转换

    DataGrid应用技巧两则(downmoon)
    一:增加求和列: 

    private void dgMeets_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
      
    {
      
       
    if(e.Item.ItemType== ListItemType.Item || e.Item.ItemType== ListItemType.Item)
       
    {
        
    //某列总和
        intTotalNew=0;
        
    int i;
        DataTable myTable;
        myTable 
    = (DataTable) ((DataSet)this.dgMeets.DataSource).Tables[0];
        
    for(i = 0;i < myTable.Rows.Count;i++)
        
    {
         intTotalNew
    +=int.Parse(myTable.Rows[i]["attendnum"].ToString());
        }

       }

       
    else if (e.Item.ItemType== ListItemType.Footer)
       
    {
        e.Item.Cells[
    6].Text = "总计:" + intTotalNew.ToString()+"";
        e.Item.Cells[
    6].Attributes.Add("Align","Right");
       }

      }

    二:列字段转换:
    方法1:

    <asp:TemplateColumn HeaderText="是否可见">
             
    <HeaderStyle HorizontalAlign="Center" Width="10%"></HeaderStyle>
             
    <ItemStyle HorizontalAlign="Center"></ItemStyle>
             
    <ItemTemplate>
              
    <asp:Label runat="server" ID="lb" Text='<%# ((DataBinder.Eval(Container, "DataItem.Conf_show", "{0}"))=="0")?"是":"<font color=red></font>" %>'> ' ></asp:Label>
             
    </ItemTemplate>
            
    </asp:TemplateColumn>

    方法2:
    后台------------

    public string ConvertToBool(string k)
      
    {
       
    string s = (k=="0")?"":"<font color=red>否</font>";
       
    return s;

      }



    前台:

     <asp:TemplateColumn HeaderText="是否可见">
             
    <HeaderStyle HorizontalAlign="Center" Width="10%"></HeaderStyle>
             
    <ItemStyle HorizontalAlign="Center"></ItemStyle>
             
    <ItemTemplate>
              
    <asp:Label runat="server" ID="lb" Text='<%# ConvertToBool(DataBinder.Eval(Container, "DataItem.Conf_show", "{0}")) %>'> ' ></asp:Label>
             
    </ItemTemplate>
            
    </asp:TemplateColumn>
    邀月注:本文版权由邀月和博客园共同所有,转载请注明出处。
    助人等于自助!  3w@live.cn
  • 相关阅读:
    写个简单的搜索引擎
    C++中的三种继承关系
    《深度探索C++对象模型》调用虚函数
    一次数据库优化的对话
    读后感:你的灯亮着吗
    Linux Shell 截取字符串
    一次关于知识储备的思考
    哈夫曼树与哈夫曼编码
    二叉查找树
    jar中没有注清单属性
  • 原文地址:https://www.cnblogs.com/downmoon/p/1018433.html
Copyright © 2011-2022 走看看