HI friends,
in this article I will explain about Bind,Save,Edit,Update,Cancel,Delete,Paging example in GridView in ASP.NET using C# or VB.NET.
I already explained in the previous articles about How to validate CheckBoxList in ASP.NET using JavaScript || Select atleast one item validation for ASP.Net CheckBoxList,How to insert multiple rows into the GridView without using any database in ASP.NET using VB.NET/C# || how to save multiple rows in GridView into a Session and How to insert the data from the TextBox into the Grid View without using any database in ASP.NET using VB.NET/C#
First of all
take one ASP.NET web page and Take one GridView and write the following ASP.NET code or simply
copy and paste the below Code.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title> How to Edit ,Update, Cancel and Delete Row in GridView
in ASP.NET using VB.NET or C#</title>
<style type ="text/css" >
.imgcls
{
width:50px;
depth:50px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="grd" runat="server" AutoGenerateColumns ="false"
AllowPaging="true" PageSize="4"
OnPageIndexChanging = "grd_PageIndexChanging"
OnRowEditing ="grd_RowEditing"
OnRowCancelingEdit ="grd_RowCancelingEdit"
OnRowUpdating ="grd_RowUpdating"
OnRowDeleting ="grd_RowDeleting" >
<Columns>
<asp:TemplateField HeaderText ="user Id">
<ItemTemplate >
<asp:Label ID="lblUID" runat="server" Text='<%#Eval("userid") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate >
<asp:TextBox ID="txtUid" runat="server" Text='<%#Eval("userid") %>' >
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="User name">
<ItemTemplate >
<asp:Label ID="lblUname" runat="server" Text='<%#Eval("username") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate >
<asp:TextBox ID="txtUname" runat="server" Text='<%#Eval("username") %>' >
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="last name">
<ItemTemplate >
<asp:Label ID="lblLname" runat="server" Text='<%#Eval("lastname") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate >
<asp:TextBox ID="txtLname" runat="server" Text='<%#Eval("lastname")%>' >
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Edit" >
<ItemTemplate>
<asp:ImageButton ID="btnEdit" ImageUrl="~/images/edit.png"
CommandName="Edit" runat="server" class="imgcls"/>
</ItemTemplate>
<EditItemTemplate >
<asp:ImageButton ID="btnUpdate" ImageUrl="~/images/edit.png"
CommandName="Update" runat="server" class="imgcls"/>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete">
<ItemTemplate >
<asp:ImageButton ID="btnDelete" ImageUrl="~/images/edit.png"
CommandName="Delete" runat="server" class="imgcls" />
</ItemTemplate>
<EditItemTemplate >
<asp:ImageButton ID="btnCancel" ImageUrl="~/images/edit.png"
CommandName="Cancel" runat="server" class="imgcls" />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Label ID="lblresult" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
|
If you
observe the code I add below code for Edit,Update,Cancel ,delete and Paging for
ASP.NET GridView and write the for that in Code behind.
C# Code
|
VB.NET
|
Click here C# code
|
Click here VB.NET code
|
No comments:
Post a Comment