You must Sign In to post a response.
  • Category: ASP.NET

    Hoe to write gridview control using thre tier

    Hi,
    how to use the below coding in three tier architecture using stored procedure for grid view conrols.


    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
    Label lbl=(Label)GridView1.Rows[e.RowIndex].FindControl("Label1");
    TextBox txt1 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox8");
    TextBox txt2 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox2");
    TextBox txt3 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox3");
    TextBox txt4 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox4");
    TextBox txt5 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox5");
    TextBox txt6 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox6");
    TextBox txt7 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox7");
    SqlConnection ocon = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ToString());
    ocon.Open();
    string query = "update postjobs set jobtitle='" + txt2.Text + "',description='" + txt3.Text + "',skills='" + txt4.Text + "',experience='" + txt5.Text + "',webaddress='" + txt7.Text + "',emailid='" + txt6.Text + "',jobcode='"+txt1.Text+"' where jobid='"+lbl.Text+"'";
    SqlCommand ocmd = new SqlCommand(query, ocon);
    ocmd.ExecuteNonQuery();
    ocon.Close();

    GridView1.EditIndex = -1;
    ocon.Open();
    string query1 = "select * from postjobs";
    SqlDataAdapter sda = new SqlDataAdapter(query1, ocon);
    DataSet ods = new DataSet();
    sda.Fill(ods, "Umeshh");
    GridView1.DataSource = ods.Tables["Umeshh"].DefaultView;
    GridView1.DataBind();
    ocon.Close();
    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
    GridView1.EditIndex = -1;
    SqlConnection ocon = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ToString());
    ocon.Open();
    string query = "select * from postjobs";
    SqlDataAdapter sda = new SqlDataAdapter(query, ocon);
    DataSet ods = new DataSet();
    sda.Fill(ods, "Umesh");
    GridView1.DataSource = ods.Tables[0].DefaultView;
    GridView1.DataBind();
    ocon.Close();
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
    Label lbl = (Label)GridView1.Rows[e.RowIndex].FindControl("Label1");
    SqlConnection ocon = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ToString());
    ocon.Open();
    string query = "delete from postjobs where jobid=" + lbl.Text;;
    SqlCommand ocmd = new SqlCommand(query, ocon);
    ocmd.ExecuteNonQuery();
    ocon.Close();


    GridView1.EditIndex = -1;
    ocon.Open();
    query = "select * from postjobs";
    SqlDataAdapter sda = new SqlDataAdapter(query, ocon);
    DataSet ods = new DataSet();
    sda.Fill(ods, "Umesh");
    GridView1.DataSource = ods.Tables[0].DefaultView;
    GridView1.DataBind();
    ocon.Close();
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
    if (e.CommandName == "Add")
    {
    TextBox t1 = (TextBox)GridView1.FooterRow.FindControl("TextBox15");
    TextBox t2 = (TextBox)GridView1.FooterRow.FindControl("TextBox9");
    TextBox t3 = (TextBox)GridView1.FooterRow.FindControl("TextBox10");
    TextBox t4 = (TextBox)GridView1.FooterRow.FindControl("TextBox11");
    TextBox t5 = (TextBox)GridView1.FooterRow.FindControl("TextBox12");
    TextBox t6 = (TextBox)GridView1.FooterRow.FindControl("TextBox13");
    TextBox t7 = (TextBox)GridView1.FooterRow.FindControl("TextBox14");

    SqlConnection ocon = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ToString());
    ocon.Open();
    string query = "insert into postjobs (jobtitle,description,skills,experience,webaddress,emailid,jobcode)values('" + t2.Text + "','" + t3.Text + "','" + t4.Text + "','" + t5.Text + "','" + t6.Text + "','" + t7.Text + "','" + t1.Text + "')";
    SqlCommand ocmd = new SqlCommand(query, ocon);
    ocmd.ExecuteNonQuery();
    ocon.Close();


    GridView1.EditIndex = -1;
    ocon.Open();
    query = "select * from postjobs";
    SqlDataAdapter sda = new SqlDataAdapter(query, ocon);
    DataSet ods = new DataSet();
    sda.Fill(ods, "Umesh");
    GridView1.DataSource = ods.Tables[0].DefaultView;
    GridView1.DataBind();
    ocon.Close();
    }
    }
    Thank u in advance.
  • #631019
    Hi this article gives complete idea about three tier architecture with gridview insert, update,delete functionality..

    http://www.dotnetfunda.com/articles/article18.aspx

  • #631028
    HI,

    Calling the BindEmpData class from the Web Form.
    grdvTest.DataSource=BLL.BindEmpData(intEmpId);
    grdvTest.DataBind();

    Method in the BLL class and it is calling the other class in the Data Access Layer.
    public static DataSet BindPlanData(int EmpId)
    {
    DataSet ds = new DataSet();
    ds = Dsll. GetEmployeeInfo(EmpId);
    return ds;
    }

    Method defined in the DAL class

    public static DataSet GetEmployeeInfo(int intEmpId)
    {
    DataSet ds;
    int QType = 2;
    try
    {
    using (SqlConnection oConnection = new SqlConnection(ApplicationConnectionString()))
    {
    SqlParameter[] parameters = new SqlParameter[1];

    parameters[0] = new SqlParameter(intEmpId, System.Data.SqlDbType.Int);
    parameters[0].Value = intEmpId

    ds = SqlHelper.ExecuteDataset(oConnection, CommandType.StoredProcedure, "mySP_GetEmployeeInfo", parameters);
    }
    return ds;
    }
    catch (Exception ex)
    {
    throw new Exception(ex.Message + " GetEmployeeInfo", ex);
    }
    }

  • #631046

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.