Here We use “Bit” DataType for Editable colume in sql server
When we use “Bit” Datatype the gridview binds the colume with Check boxes automatically
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUsBInYUU37SIIR1PRZJu6LQeEs7ssZyF5CuQ_slA0DpoVP5rhUdt4sCt9BhOgIT1UlMpSsffPGCJSvb3op2xv-7BM4528xlzjP2_TrcwEJroreM801mXIYURMch2jiKWM0U6QCdgpew4/s400/noneditablerowingv2.bmp)
Productid (int) | Productname (Varchar) | price (int) | editable (bit) |
---|---|---|---|
1 | keyboard | 500 | True |
2 | Monitor | 5000 | False |
3 | mouse | 400 | False |
4 | HDD | 3000 | True |
in .CS file
public partial class _Default : System.Web.UI.Page
{
SqlConnection con; SqlDataAdapter da; SqlCommand cmd; DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{
con = new SqlConnection("server=FOCALPOI-392A7D\\SQLEXPRESS;user id=raji;password=chekuri;database=raji");
if (IsPostBack == false)
{
getdata();
}
}
public void getdata()
{
da = new SqlDataAdapter("select * from product", con);
ds = new DataSet();
da.Fill(ds, "product");
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
Label1.Text = "";
GridViewRow r = GridView1.Rows[e.NewEditIndex];
CheckBox cb = (CheckBox)r.Cells[4].Controls[0];
//if the Check box in editable colume is checked then the colume is allow to edit
//if not then it is non Editable colume
if (cb.Checked)
{
GridView1.EditIndex = e.NewEditIndex;
getdata();
}
else
{
Label1.Text = "This Is Non Editable Item";
}
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
getdata();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridView1.EditIndex = -1;
getdata();
}
}
0 comments:
Respects for your's Questions & Opinions