gridview+checkbox

using System;
using System.Collections;
using System.Configuration;
using System.Data;

public partial class Apps_repository_faqConfirm : System.Web.UI.Page
{

    #region 变量

    #endregion

    #region 事件方法
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadPage();

            tableTitle.Text = "待审批";
            prepareViewed.Visible = false;
        }     
    }

    //全部选择
    protected void selectAll_Click(object sender, EventArgs e)
    {

        for (int i = 0; i < this.GridView1.Rows.Count; i++)
        {
            ((CheckBox)GridView1.Rows[i].FindControl("chkSelect")).Checked = true;
        }
    }

    // 全部评分
    protected void scoreAll_Click(object sender, EventArgs e)
    {
        string scoreValue = ddlScoreAll.SelectedValue;

        int stringCount = GridView1.Rows.Count;

        for (int i = 0; i < stringCount; i++)
        {
            if (((CheckBox)GridView1.Rows[i].FindControl("chkSelect")).Checked)
            {
                ((DropDownList)GridView1.Rows[i].FindControl("ddlScore")).SelectedValue = scoreValue;
            }
        }
    }

    //审批通过
    protected void passAll_Click(object sender, EventArgs e)
    {
        UpDatePassData();
        LoadPage();
    }

    //拒绝通过
    protected void rejectAll_Click(object sender, EventArgs e)
    {

        UpDateRejectData();
        LoadPage();

    }

    //待审批
    protected void prepareViewed_Click(object sender, EventArgs e)
    {
        Response.Redirect(this.Request.Url.ToString());
    }

    //已审批通过
    protected void viewed_Click(object sender, EventArgs e)
    {
        LoadPassData();

        tableTitle.Text = "已审批通过";

        passAll.Enabled = false;
        rejectAll.Enabled = false;
        scoreAll.Enabled = false;
        prepareViewed.Visible = true;

    }
   
    //未审批通过
    protected void notViewed_Click(object sender, EventArgs e)
    {
        LoadRejectData();

        tableTitle.Text = "未审批通过";

        passAll.Enabled = false;
        rejectAll.Enabled = false;
        scoreAll.Enabled = false;
        prepareViewed.Visible = true;
    }

    #endregion

    #region 私有方法

    public void LoadPage()
    {
        string sql = "select *From t_info where info_check=0";

        DataTable dt = MySQLHelper.GetDataTable(sql);

        GridView1.DataSource = dt;
        GridView1.DataBind();
    }

    public void LoadPassData()
    {

        string sql = "select *From t_info where info_check=1";
        DataTable dt = MySQLHelper.GetDataTable(sql);

        GridView1.DataSource = dt;
        GridView1.DataBind();

        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            ((DropDownList)(GridView1.Rows[i].FindControl("ddlScore"))).SelectedValue = dt.Rows[i]["info_score"].ToString();

        }
    }

    public void LoadRejectData()
    {
        string sql = "select *From t_info where info_check=2";
        DataTable dt = MySQLHelper.GetDataTable(sql);

        GridView1.DataSource = dt;
        GridView1.DataBind();

        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            ((DropDownList)(GridView1.Rows[i].FindControl("ddlScore"))).SelectedValue = dt.Rows[i]["info_score"].ToString();

        }
    }

    /// <summary>
    /// 检查选择项 返回选择项INFO_ID数组
    /// </summary>
    /// <returns>INFO_ID</returns>
    public string[,] CheckIsSelected()
    {
        int stringCount = GridView1.Rows.Count;

        string[,] isSelected = new string[2, stringCount];

        for (int i = 0; i < stringCount; i++)
        {
            if (((CheckBox)GridView1.Rows[i].FindControl("chkSelect")).Checked)
            {
                isSelected[0, i] = GridView1.DataKeys[GridView1.Rows[i].RowIndex].Value.ToString();
                isSelected[1, i] = ((DropDownList)(GridView1.Rows[i].FindControl("ddlScore"))).SelectedValue;
            }
        }

        return isSelected;
    }

    /// <summary>
    /// 更新审批拒绝数据
    /// </summary>
    public void UpDateRejectData()
    {
        string[,] info_Score = CheckIsSelected();
        for (int i = 0; i < info_Score.Length / 2; i++)
        {
            if (info_Score[0, i] != null)
            {
                string sql = string.Format("update t_info set info_check=2 ,Info_Score={0} where Info_id ={1} ", info_Score[1, i], info_Score[0, i]);
                MySQLHelper.ExecuteNonQuery(sql);
            }

        }
    }

    /// <summary>
    /// 更新审批通过数据
    /// </summary>
    public void UpDatePassData()
    {
        string[,] info_Score = CheckIsSelected();

        for (int i = 0; i < info_Score.Length / 2; i++)
        {
            if (info_Score[0, i] != null)
            {
                string sql = string.Format("update t_info set info_check =1,Info_Score={0} where info_id= {1}", info_Score[1, i], info_Score[0, i]);
                MySQLHelper.ExecuteNonQuery(sql);
            }
        }
    }
   
    #endregion

 

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值