Friday, December 17, 2010

Non Editable Rows in GridView

0 comments 12/17/2010
Sign up to receive our site updates!
In This example A GridView containes non editable rows,

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







Productid (int)Productname (Varchar)price (int)editable (bit)
1keyboard500True

2Monitor5000False
3mouse400False
4HDD3000True






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();
}
}


Your Ad Here

0 comments:

Respects for your's Questions & Opinions

  • Friends
  •  

    Recent Posts

    New Comments

    Copyright 2008 All Rights Reserved Tech Tasks Template by Rajesh Kumar Chekuri

    Share
    Me
    Twitter Facebook Google +1 Pinterest Delicious Digg Stumbleupon More

    Connect to TT Facebook Google +1
    Back to Top