Click here to Skip to main content
11,641,971 members (60,287 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET Gridview buttons , +
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:
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 29-Jun-13 2:59am

1 solution

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

  Print Answers RSS
0 DamithSL 245
1 Afzaal Ahmad Zeeshan 170
2 Sergey Alexandrovich Kryukov 159
3 OriginalGriff 110
4 Mika Wendelius 90
0 Mika Wendelius 460
1 DamithSL 353
2 OriginalGriff 315
3 Sergey Alexandrovich Kryukov 179
4 Afzaal Ahmad Zeeshan 169


Advertise | Privacy | Mobile
Web03 | 2.8.150731.1 | Last Updated 29 Jun 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100