Friday, 27 June 2014

Checkbox and Gridview code behind file

using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class StudentMarks : System.Web.UI.Page
{
    public SqlConnection con = new SqlConnection("Data Source=THIYAGU-PC\\SQLEXPRESS;Initial Catalog=TEST;Integrated Security=True");
    public SqlCommand cmd;
    public DataSet ds;
    SqlDataAdapter da;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            viewdata();
        }

    }
    protected void txt_m4_TextChanged(object sender, EventArgs e)
    {
        int a = Convert.ToInt32(txt_m1.Text);
        int b = Convert.ToInt32(txt_m2.Text);
        int c = Convert.ToInt32(txt_m3.Text);
        int d = Convert.ToInt32(txt_m4.Text);
        int f = a + b + c +d ;
        txt_tot.Text = Convert.ToString(f);
    }
    protected void gvCheckboxes_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void gvCheckboxes_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow &&
   (e.Row.RowState == DataControlRowState.Normal ||
    e.Row.RowState == DataControlRowState.Alternate))
        {
            CheckBox chkBxSelect = (CheckBox)e.Row.Cells[1].FindControl("chkBxSelect");
            CheckBox chkBxHeader = (CheckBox)this.gvCheckboxes.HeaderRow.FindControl("chkBxHeader");
            chkBxSelect.Attributes["onclick"] = string.Format
                                                   (
                                                      "javascript:ChildClick(this,'{0}');",
                                                      chkBxHeader.ClientID
                                                   );
        }
    }
    protected void Btn_Submit_Click(object sender, EventArgs e)
    {
        con.Open();
        cmd = new SqlCommand("sp_student", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@Sname", txt_Sname.Text);
        cmd.Parameters.AddWithValue("@m1", txt_m1.Text);
        cmd.Parameters.AddWithValue("@m2", txt_m2.Text);
        cmd.Parameters.AddWithValue("@m3", txt_m3.Text);
        cmd.Parameters.AddWithValue("@m4", txt_m4.Text);
        cmd.ExecuteNonQuery();
        con.Close();
        viewdata();
     
    }

    public DataSet viewdata()
    {
        cmd = new SqlCommand("select *from Student",con);
        da = new SqlDataAdapter(cmd);
        ds=new DataSet();
        da.Fill(ds);
        gvCheckboxes.DataSource = ds;
        gvCheckboxes.DataBind();
        con.Close();
        return ds;
       
    }

}

No comments:

Post a Comment