using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;

public partial class ManagerList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            display();
        }
    }
    SqlCommand cmd;
    int id;
    SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings.Get("con"));

    private void display()
    {
        if (con.State == ConnectionState.Closed) con.Open();
        SqlDataAdapter da = new SqlDataAdapter("select docno from data where status is null", con);
        DataSet ds = new DataSet();
        da.Fill(ds, "data");
        DataGrid1.DataSource = ds.Tables[0];
        DataGrid1.DataBind();
        con.Close();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Panel1.Visible = false;
        try
        {
            foreach (DataGridItem c in DataGrid1.Items)
            {
                if ((((CheckBox)(c.FindControl("chk"))).Checked) == true)
                {
                    con.Open();
                    id = Convert.ToInt32(c.Cells[1].Text);
                    cmd = new SqlCommand("update data set status='yes' where docno=" + id, con);
                    cmd.ExecuteNonQuery();
                    con.Close();
                }
            }
        }
        catch (Exception ex)
        {
            lbltext.Text = ex.Message;
        }
        display();
    }
    protected void DataGrid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
    {
        DataGrid1.CurrentPageIndex = e.NewPageIndex;
        display();
    }
    protected void DataGrid1_DeleteCommand(object source, DataGridCommandEventArgs e)
    {
        if (con.State == ConnectionState.Closed) con.Open();
        SqlCommand cmd = new SqlCommand("select subject from data where docno=" + e.Item.Cells[1].Text, con);
        TextBox1.Text = cmd.ExecuteScalar().ToString();
        con.Close();
        Panel1.Visible = true;
    }
}
