Wednesday, 2 October 2013

Bind,Save,Edit,Update,Cancel,Delete,Paging example in GridView in ASP.NET using C# or VB.NET

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.
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

© 2012-2018 Aspdotnet-Kishore.blogspot.com. All Rights Reserved.
The content is copyrighted to Kishore and may not be reproduced on other websites without permission from the owner.