Friday, November 26, 2010

vwRegistrations using checkboxes

public partial class Admin_VwRegistrations : System.Web.UI.Page
{
    DBUpdate registration = new DBUpdate();
    DataTable dt = new DataTable();
    string rid;
    protected void Page_Load(object sender, EventArgs e)
    {

       // lblrid.Text = k;
        if (!Page.IsPostBack)
        {
            LoadData();
           
        }

    }
    private void LoadData()
    {
        //string constr = @"Server=.\SQLEXPRESS;Database=TestDB;uid=waqas;pwd=sql;";
        string query = @"SELECT * FROM tblReporterRegistration where status =''" ;
     try
        {
        SqlDataAdapter da = new SqlDataAdapter(query, registration.con);
      
            da.Fill(dt);
            object k = dt.Rows[0][0].ToString();
            lblrid.Text = k.ToString();
        }
       
       catch (Exception ex)
        {
            
             Response.Write("<script>alert('Existing Registrations are empty...')</script>");
             // clearall();
             StringBuilder sb = new StringBuilder();
             sb.Append("<script>");
             sb.Append("window.open('adminHome.aspx', '', '');");
             sb.Append("</scri");
             sb.Append("pt>");

             Page.RegisterStartupScript("test", sb.ToString());
        }
       
        GridView1.DataSource = dt;
        GridView1.DataBind();
   
      
     
}
       private void clientScriptAlert(string Message)
    {
        Page.RegisterClientScriptBlock("clientScript", "<script>alert('" + Message + "')</script>");
    }   
   
  
    protected void CheckBox3_CheckedChanged(object sender, EventArgs e)
    {
       CheckBox chkStatus = (CheckBox)sender;
        GridViewRow row = (GridViewRow)chkStatus.NamingContainer;

          rid = lblrid.Text;

         // rid = row.Cells[1].Text;//(CheckBox)row.FindControl("cbRows")

        bool status = chkStatus.Checked;


       // CheckBox checkbox = (CheckBox)row.FindControl("regnId");
    
        registration.con.Open();

        string query = "UPDATE tblReporterRegistration SET status = 'Active' WHERE regnID = " + rid;
        string query2 = "UPDATE tblUser SET status = 'Active' WHERE registrationid = " + rid;

        //SqlConnection con = new SqlConnection(constr);
        SqlCommand com = new SqlCommand(query, registration.con);
        SqlCommand cmd = new SqlCommand(query2, registration.con);

        com.Parameters.Add("@Approved", SqlDbType.Bit).Value = status;
        com.Parameters.Add("@CategoryID", SqlDbType.Int).Value = rid;


      //  registration.con.Open();
        com.ExecuteNonQuery();
        cmd.ExecuteNonQuery();
        registration.con.Close();
        LoadData();


   
}
   
  
    //protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    //{
    //    string strupdate = "update tblReporterRegistration set  status = 'Active' where regnId =  " +  ;
    //    registration.excquery(strupdate);
    //}
    //protected void btnAccept_Click1(object sender, EventArgs e)
    //{
    //    string strupdate = "update tblReporterRegistration set  status = 'Active' where regnId =  " + rid;
    //    registration.excquery(strupdate);
    //}
    //protected void btnReject_Click1(object sender, EventArgs e)
    //{
    //    string strdelete = "delete from  tblReporterRegistration   where regnId =  " + rid;
    //    registration.excquery(strdelete);
    //}
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
        CheckBox chkStatus = (CheckBox)sender;
        GridViewRow row = (GridViewRow)chkStatus.NamingContainer;

        rid = lblrid.Text;

        // rid = row.Cells[1].Text;//(CheckBox)row.FindControl("cbRows")

        bool status = chkStatus.Checked;


        // CheckBox checkbox = (CheckBox)row.FindControl("regnId");

        registration.con.Open();

        string query = "UPDATE tblReporterRegistration SET status = 'Active' WHERE regnID = " + rid;
        string query2 = "UPDATE tblUser SET status = 'Active' WHERE registrationid = " + rid;

        //SqlConnection con = new SqlConnection(constr);
        SqlCommand com = new SqlCommand(query, registration.con);
        SqlCommand cmd = new SqlCommand(query2, registration.con);

        com.Parameters.Add("@Approved", SqlDbType.Bit).Value = status;
        com.Parameters.Add("@CategoryID", SqlDbType.Int).Value = rid;


        //  registration.con.Open();
        com.ExecuteNonQuery();
        cmd.ExecuteNonQuery();
        registration.con.Close();
        LoadData();

    }
}

No comments:

Post a Comment