绑定到gridview的复选框与日期相关 [英] binding checkboxes to gridview with respect to date

查看:59
本文介绍了绑定到gridview的复选框与日期相关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Everyone,





我们如何使用数据表动态地根据工作日将复选框绑定到gridview



例如:学校的出勤登记



提前感谢

解决方案

在GridView中手动添加复选框:

  protected   void  Page_Load( object  sender,EventArgs e)
{
if (!IsPostBack)
{
System.Data.DataTable dt = GetTable();
ViewState [ dt] = dt;
GridView1.DataSource = dt;
GridView1.DataBind();
}

AddCheckBox();
}

void AddCheckBox()
{
System.Data.DataTable dt =(System。 Data.DataTable)ViewState [ dt];
for int i = 0 ; i < dt.Rows.Count; i ++)
{
if (GridView1.Rows [i] .Cells [ 0 ]。Controls.Count == 0
{
CheckBox cb = new CheckBox();
GridView1.Rows [i] .Cells [ 0 ]。Controls.Add(cb);
}
}
}

void GetCheckBoxValue()
{
foreach (GridViewRow gr in GridView1.Rows)
{
bool cbValue =((CheckBox)gr.Cells [ 0 ]。控件[ 0 ])经过。

// 做点什么
}
}


Hello Everyone,


how can we bind checkboxes to the gridview dynamically according to the monthdays using datatables

eg:attendance register of schools

thanks in advance

解决方案

Manually add checkbox into GridView:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        System.Data.DataTable dt = GetTable();
        ViewState["dt"] = dt;
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }

    AddCheckBox(); 
}

void AddCheckBox()
{
    System.Data.DataTable dt = (System.Data.DataTable)ViewState["dt"];
    for (int i = 0; i < dt.Rows.Count; i++)
    {
        if (GridView1.Rows[i].Cells[0].Controls.Count == 0)
        {
            CheckBox cb = new CheckBox();
            GridView1.Rows[i].Cells[0].Controls.Add(cb);
        }
    }
}

void GetCheckBoxValue()
{
    foreach (GridViewRow gr in GridView1.Rows)
    {
        bool cbValue = ((CheckBox)gr.Cells[0].Controls[0]).Checked;

        // do something
    }
}


这篇关于绑定到gridview的复选框与日期相关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆