| TechTasks.net |
The Blog is Moved to www.TechTasks.net
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
<asp:GridView ID="GridView1" runat="server" AutoGenerateEditButton="True" DataKeyNames="productid,editable"
OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowEditing="GridView1_RowEditing"
OnRowUpdating="GridView1_RowUpdating" Style="z-index: 100; left: 222px; position: absolute;
top: 75px">
asp:GridView>
<asp:Label ID="Label1" runat="server" Font-Size="Large" ForeColor="Red" Style="z-index: 102;
left: 311px; position: absolute; top: 51px">asp:Label>
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();
}
}
Blog Archive
-
▼
2008
(33)
-
▼
December
(14)
- Non Editable Rows in GridView
- Validate DropDownList inside GRIDVIEW
- .Net Keyboard Shortcuts
- Grid View Operataions
- FAQ'S & INTERVIEW TIPS
- C#.NET
- ASP.NET
- DOTNET FRAMEWORK
- Projects With Source Code
- Enter Text In Into Two TextBoxes At the Same Time
- Saving Uploaded file into Disk and displaying the ...
- Writing Connection string in web.config file
- Change GridView Row Color When MouseOver
- Working With Command Builder in ASP.NET
-
►
November
(14)
- JavaScript Validatoin For Basic Controles in ASP.N...
- Dot Net - C#.Net(FAQ'S)
- Dot Net - Asp.Net - Basic II(FAQ'S)
- Dot Net - Asp.Net - Basic I(FAQ'S)
- Famous Books For .NET
- Connecting MySql With Asp.net Using ODBC Drivers
- Simple Calculator In Windows Application Using C#
- Mail Sending Using Net.Mail
- Select All And Delete Using CheckBox In GridView
- GridView DeleteAll,SelectAll,ClearAll(Server Side)...
- GridView Paging & Sorting
- GridView Update,Delete,Adding (Insert) Record...
- Alphabetical Paging in Gridview
- Connecting MySql With C# ASP.NET
-
▼
December
(14)




2 comments:
Thanx a lot for the great, informative article, saved me by providing this post, keep doing many.
Great tutorial, nicely explained, most useful post, keep doing.