Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Dynamically adding and deleting rows from ASP.NET GridView

, 8 Jan 2014
This article talks about a small project that presents the idea of having a gridview which facilitate the addition and removal of rows dynamically at run time.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
    <title>Add Dynamic Rows In Gridview</title>
    <form id="form1" runat="server">
            <asp:GridView ID="grvStudentDetails" runat="server" ShowFooter="True" AutoGenerateColumns="False"
                CellPadding="4" ForeColor="#333333" GridLines="None" OnRowDeleting="grvStudentDetails_RowDeleting">
                    <asp:BoundField DataField="RowNumber" HeaderText="SNo" />
                    <asp:TemplateField HeaderText="Student Name">
                            <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
                    <asp:TemplateField HeaderText="Student Age">
                            <asp:TextBox ID="txtAge" runat="server"></asp:TextBox>
                    <asp:TemplateField HeaderText="Student Address">
                            <asp:TextBox ID="txtAddress" runat="server" Height="55px" TextMode="MultiLine"></asp:TextBox>
                    <asp:TemplateField HeaderText="Gender">
                            <asp:RadioButtonList ID="RBLGender" runat="server" RepeatDirection="Horizontal">
                                <asp:ListItem Value="M">Male</asp:ListItem>
                                <asp:ListItem Value="F">Female</asp:ListItem>
                    <asp:TemplateField HeaderText="Qualification">
                            <asp:DropDownList ID="drpQualification" runat="server">
                                <asp:ListItem Value="G">Graduate</asp:ListItem>
                                <asp:ListItem Value="P">Post Graduate</asp:ListItem>
                        <FooterStyle HorizontalAlign="Right" />
                            <asp:Button ID="ButtonAdd" runat="server" Text="Add New Row" OnClick="ButtonAdd_Click" />
                    <asp:CommandField ShowDeleteButton="True" />
                <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <RowStyle BackColor="#EFF3FB" />
                <EditRowStyle BackColor="#2461BF" />
                <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <AlternatingRowStyle BackColor="White" />

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
India India
I am a Software Engineer from Bhopal. I started my Career from Programming in ASP and now working as a Web Developer in ASP.Net (C#). I Love coding and always ready to gain new thing and always been towards Microsoft Technologies. Apart from coding my other hobbies are traveling, Internet Surfing, spending time with family and hang out with friends.
Follow on   Twitter   Google+

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 9 Jan 2014
Article Copyright 2012 by AshishChaudha
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid