Here the document explains that how to create the simple GridView and binding it with the sample data table in the application itself without using the database.
First, Create a sample user form and save the details those are entered in the form and the saved details should bind with the GridView. The source code as follows,
- <%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="userdata.aspx.cs"Inherits="WebApplication17.userdata"%>
- <!DOCTYPEhtml>
- <htmlxmlns="http://www.w3.org/1999/xhtml">
- <headrunat="server">
- <title></title>
- </head>
- <body>
- <formid="form1" runat="server">
- <divalign="center">
- <table>
- <tr>
- <tdcolspan="3">USER FORM</td>
- </tr>
- </table>
- <table>
- <tr>
- <td>
- <asp:LabelID="Label1" runat="server" Text="Enter UserName"></asp:Label>
- </td>
- <td>
- <asp:TextBoxID="TextBox1" runat="server"></asp:TextBox>
- </td>
- </tr>
- <tr>
- <td>
- <asp:LabelID="Label2" runat="server" Text="Enter Password"></asp:Label>
- </td>
- <td>
- <asp:TextBoxID="TextBox2" runat="server" TextMode="Password"></asp:TextBox>
- </td>
- </tr>
- <tr>
- <td>
- <asp:LabelID="Label3" runat="server" Text="Confirm Password"></asp:Label>
- </td>
- <td>
- <asp:TextBoxID="TextBox3" runat="server" TextMode="Password"></asp:TextBox>
- </td>
- </tr>
- <tr>
- <td>
- <asp:LabelID="Label4" runat="server" Text="Email ID"></asp:Label>
- </td>
- <td>
- <asp:TextBoxID="TextBox4" runat="server"></asp:TextBox>
- </td>
- </tr>
- <tr>
- <td>
- <asp:LabelID="Label5" runat="server" Text="Address"></asp:Label>
- </td>
- <td>
- <asp:TextBoxID="TextBox5" runat="server"></asp:TextBox>
- </td>
- </tr>
- <tr>
- <td>
- <asp:LabelID="Label6" runat="server" Text="Contact Number"></asp:Label>
- </td>
- <td>
- <asp:TextBoxID="TextBox6" runat="server"></asp:TextBox>
- </td>
- </tr>
- <tr>
- <td>
- <asp:LabelID="Label7" runat="server" Text="Gender"></asp:Label>
- </td>
- <td>
- <asp:RadioButtonListID="RadioButtonList1" runat="server" RepeatDirection="Horizontal" Width="134px">
- <asp:ListItem>Male</asp:ListItem>
- <asp:ListItem>Female</asp:ListItem>
- </asp:RadioButtonList>
- </td>
- </tr>
- </table>
- <table>
- <tr>
- <td>
- <asp:ButtonID="Button1" runat="server" Text="Save Your Data" OnClick="Button1_Click" />
- </td>
- </tr>
- </table>
- </div>
- <divalign="center">
- <asp:GridViewID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None">
- <AlternatingRowStyleBackColor="White" />
- <EditRowStyleBackColor="#7C6F57" />
- <FooterStyleBackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
- <HeaderStyleBackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
- <PagerStyleBackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
- <RowStyleBackColor="#E3EAEB" />
- <SelectedRowStyleBackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
- <SortedAscendingCellStyleBackColor="#F8FAFA" />
- <SortedAscendingHeaderStyleBackColor="#246B61" />
- <SortedDescendingCellStyleBackColor="#D4DFE1" />
- <SortedDescendingHeaderStyleBackColor="#15524A" />
- </asp:GridView>
- <br/>
- </div>
- </form>
- </body>
- </html>
- using System;
- using System.Collections.Generic;
- using System.Linq;
- Using System.Web;
- Using System.Web.UI;
- Using System.Web.UI.WebControls;
- Using System.Data;
- Protectedvoid Button1_Click(object sender, EventArgs e)
- {
- DataTabledt = newDataTable();
- dt.Columns.Add("Username", typeof(string));
- dt.Columns.Add("Password", typeof(string));
- dt.Columns.Add("Email ID", typeof(string));
- dt.Columns.Add("Address", typeof(string));
- dt.Columns.Add("Contact", typeof(string));
- dt.Columns.Add("Gender", typeof(string));
- If(TextBox2.Text == TextBox3.Text)
- {
- dt.Rows.Add(TextBox1.Text, TextBox2.Text, TextBox4.Text, TextBox5.Text, RadioButtonList1.SelectedItem.Text);
- GridView1.DataSource = dt;
- GridView1.DataBind();
- } else
- {
- Response.Write("<script>alert ('Password and ConformPassword are not matched') ;< /script>");
- }
- }

Shiva VPosted Dec 23, 2015, 4:18 AM
If(TextBox2.Text==TextBox3.text) {dt.Rows.Add(TextBox1.Text, TextBox2.Text, TextBox4.Text, TextBox5.Text, RadioButtonList1.SelectedItem.Text); GridView1.DataSource = dt; GridView1.DataBind(); }
Shiva VPosted Dec 23, 2015, 4:17 AM
Sorry I forget to mention the code to check the password and confirm password as follows,