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
  • 相关阅读:
    P2890 [USACO07OPEN]Cheapest Palindrome G 题解
    「NOIP2021模拟赛 By JXC C」位运算 题解
    AT5759 ThREE 题解
    P7532 [USACO21OPEN] Balanced Subsets P 题解
    linux下的pdf分割合并软件
    Python小练习 SDUT 2521 出现次数
    小问题备查持续更新
    Python小练习自动登录人人发送消息并返回好友列表
    Debian系使用小红点
    linux权限问题学习总结
  • 原文地址:https://www.cnblogs.com/downmoon/p/1018433.html
Copyright © 2011-2022 走看看