.aspx Code:
aspx.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data.SqlClient;
- using System.Configuration;
- using System.Data;
- public partial class DoctorApprovList : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- gvbind();
- }
- }
-
- protected void gvbind()
- {
- SqlConnection con = new SqlConnection();
- con.ConnectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString();
- con.Open();
- SqlDataAdapter sda = new SqlDataAdapter("Select * from DOC_REG1 where status='T'", con);
- DataSet ds = new DataSet();
- sda.Fill(ds);
- GridView1.DataSource = ds;
- GridView1.DataBind();
- }
-
- protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
- {
- int code = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
- SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString());
- con.Open();
- string query1 = "delete from DOC_REG1 where code=" + code+ "";
- SqlCommand cmd = new SqlCommand(query1, con);
- cmd.ExecuteNonQuery();
- gvbind();
- lblMessage.Text = "RECORD DELETED SUCCESSFULLY";
- con.Close();
- }
- protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
- {
- GridView1.EditIndex = e.NewEditIndex;
- gvbind();
- }
- protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
- {
- GridView1.EditIndex = -1;
- gvbind();
- }
-
- protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- DataRowView dRowView = (DataRowView)e.Row.DataItem;
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- if ((e.Row.RowState & DataControlRowState.Edit) > 0)
- {
- DropDownList ddlWork = (DropDownList)e.Row.FindControl("ddlWork");
- DropDownList ddlDept = (DropDownList)e.Row.FindControl("ddlDept");
- ddlWork.SelectedValue = dRowView[3].ToString();
- ddlDept.SelectedValue = dRowView[4].ToString();
- }
- }
- }
-
- protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
- {
- int code= Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
- GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
- TextBox txt = (TextBox)row.FindControl("txtPass");
- string newpass = txt.Text;
- txt = (TextBox)row.FindControl("txtDocname");
- string newDocname = txt.Text;
- DropDownList ddlWork = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlWork");
- DropDownList ddlDept = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlDept");
- txt = (TextBox)row.FindControl("txtMobno");
- int newMob = Convert.ToInt32(txt.Text);
- txt = (TextBox)row.FindControl("txtAdd");
- string newaddress = txt.Text;
- SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString());
- con.Open();
- string query = "update DOC_REG1 set pass='" + newpass + "',dname='" + newDocname + "',wexp='" + ddlWork.SelectedValue + "',dept='" + ddlDept.SelectedValue + "',mobno='" + newMob + "',address='" + newaddress + "' where code='" +code+ "'";
- SqlCommand cmd = new SqlCommand(query, con);
- cmd.ExecuteNonQuery();
- GridView1.EditIndex = -1;
- gvbind();
- con.Close();
- }
- }
In the case of radiobuttonlist,we use codes in the place of dropdownlist as shown below:
-
- protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
- {
-
- RadioButtonList rblGender= (RadioButtonList)e.Row.FindControl("rblGender");
- rblGender.SelectedValue = dRowView[2].ToString();
- }
And
- protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
- {
-
- RadioButtonList rblGen= (RadioButtonList)GridView1.Rows[e.RowIndex].FindControl("rblGender");
-
- }