zoukankan      html  css  js  c++  java
  • GridView绑定数据后想要更换每个单元格中内容的方法

     上一个篇写的不明确,这篇进行详细的解释:

    1,首先是GridView控件有一个事件就是GridView1_RowDataBound,此事件是在设置了GridView的绑定后每绑定一条数据就会执行一次的;

    2,参数e是传过来的GridView1,此时可以对GridView1进行设置了,e.Row.RowType是指GridView1中每行的类型,一般在DataControlRowType中,如:DataControlRowType.DataRow(数据行),其中还有Pager(显示导航按钮的行)、Header(表头)、Footer(脚注释)、Separator(行分隔符)等。

    3,例子如下该GridView控件的ID="GridTimezone"。

    protected void GridTimezone_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.DataRow) //如果是数据行
                {
                    var obj = (BaseInfo_BusinessTimeConfig)e.Row.DataItem;
                    e.Row.Cells[2].Text = obj.DayStart + ":00";
                    e.Row.Cells[3].Text = obj.DayEnd + ":00";
                    e.Row.Cells[4].Text = obj.MonthStart  + "日";
                    e.Row.Cells[5].Text = obj.MonthEnd + "日";
                    e.Row.Cells[6].Text = obj.YearStart  + "月";
                    e.Row.Cells[7].Text = obj.YearEnd + "月";
                    if (obj.WeekStart == 0)
                    {
                        e.Row.Cells[8].Text="周日";
                    }
                    else
                    {
                        e.Row.Cells[8].Text ="周"+obj.WeekStart.ToString();
                    }
                    if (obj.WeekEnd == 0)
                    {
                        e.Row.Cells[9].Text = "周日";
                    }
                    else
                    {
                        e.Row.Cells[9].Text = "周" + obj.WeekEnd.ToString();
                    }
                }
            }

  • 相关阅读:
    leetcode 13. Roman to Integer
    python 判断是否为有效域名
    leetcode 169. Majority Element
    leetcode 733. Flood Fill
    最大信息系数——检测变量之间非线性相关性
    leetcode 453. Minimum Moves to Equal Array Elements
    leetcode 492. Construct the Rectangle
    leetcode 598. Range Addition II
    leetcode 349. Intersection of Two Arrays
    leetcode 171. Excel Sheet Column Number
  • 原文地址:https://www.cnblogs.com/hanwenhua/p/2782665.html
Copyright © 2011-2022 走看看