Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
This question can be ask here many time but my case is different. Please forgive me if i am wrong i have a page in which i have text-box and a button when i enter department name in text-box and press submit button my data store in the database

Now what i want is i want
(1) When i press submit button i can see that department in my grid-view.
(2) to show my department name in grid with edit and delete link so that when i click on edit link department name will pop in the department text-box and submit button become update button and when i make some changes and click on update button it will update and show it in the grid.

how can i do that This is my department page.cs code:
C#
public partial class DepartmentMaster : System.Web.UI.Page
 {
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["WebGallery"].ToString());
SqlDataAdapter da; DataTable dt = new DataTable();
 DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{ if (!IsPostBack)
{
con.Open();
da = new SqlDataAdapter("Select * from Department_Master", con); da.Fill(ds);
gvDepartment.DataSource = ds;
 gvDepartment.DataBind();
con.Close(); 
} 
}
 protected void btnSubmit_Click(object sender, EventArgs e)
 { using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyGallery"].ToString()))
 {
con.Open(); string DepartmentName = tbDepartment.Text.Trim();
 using (SqlCommand cmd = con.CreateCommand())
{
cmd.CommandText = "insert into Department_Master(DepartmentName) values('" + DepartmentName + "')";
cmd.Parameters.AddWithValue("@DepartmentName", tbDepartment.Text.Trim());
cmd.ExecuteNonQuery();
}
con.Close();
tbDepartment.Text = "";
tbDepartment.Focus();
} 
}
}
Posted

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900