<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CrudGrid.aspx.cs" Inherits="IUDvnbvn.CrudGrid" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:SampleConnectionString %>" DeleteCommand="DELETE FROM [tblCompanyEmployee] WHERE [EmployeeId] = @EmployeeId" InsertCommand="INSERT INTO [tblCompanyEmployee] ([Name], [Gender], [City]) VALUES (@Name, @Gender, @City)" SelectCommand="SELECT * FROM [tblCompanyEmployee]" UpdateCommand="UPDATE [tblCompanyEmployee] SET [Name] = @Name, [Gender] = @Gender, [City] = @City WHERE [EmployeeId] = @EmployeeId" OnInserted="SqlDataSource1_Inserted"> <deleteparameters> <asp:Parameter Name="EmployeeId" Type="Int32" /> </deleteparameters> <insertparameters> <asp:Parameter Name="Name" Type="String" /> <asp:Parameter Name="Gender" Type="String" /> <asp:Parameter Name="City" Type="String" /> </insertparameters> <updateparameters> <asp:Parameter Name="Name" Type="String" /> <asp:Parameter Name="Gender" Type="String" /> <asp:Parameter Name="City" Type="String" /> <asp:Parameter Name="EmployeeId" Type="Int32" /> </updateparameters> <br /> <br /> <br /> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="EmployeeId" DataSourceID="SqlDataSource1" ShowFooter="True"> <columns> <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" /> <asp:TemplateField HeaderText="EmployeeId" InsertVisible="False" SortExpression="EmployeeId"> <edititemtemplate> <asp:Label ID="Label1" runat="server" Text='<%# Eval("EmployeeId") %>'> </edititemtemplate> <footertemplate> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /> </footertemplate> <itemtemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("EmployeeId") %>'> </itemtemplate> <asp:TemplateField HeaderText="Name" SortExpression="Name"> <edititemtemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Name") %>'> </edititemtemplate> <footertemplate> <asp:TextBox ID="TextBox4" runat="server"> </footertemplate> <itemtemplate> <asp:Label ID="Label2" runat="server" Text='<%# Bind("Name") %>'> </itemtemplate> <asp:TemplateField HeaderText="Gender" SortExpression="Gender"> <edititemtemplate> <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Gender") %>'> </edititemtemplate> <footertemplate> <asp:DropDownList ID="DropDownList1" runat="server"> <asp:ListItem>Select Gender <asp:ListItem>Male <asp:ListItem>Female </footertemplate> <itemtemplate> <asp:Label ID="Label3" runat="server" Text='<%# Bind("Gender") %>'> </itemtemplate> <asp:TemplateField HeaderText="City" SortExpression="City"> <edititemtemplate> <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("City") %>'> </edititemtemplate> <footertemplate> <asp:TextBox ID="TextBox5" runat="server"> </footertemplate> <itemtemplate> <asp:Label ID="Label4" runat="server" Text='<%# Bind("City") %>'> </itemtemplate> </columns> </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; namespace IUDvnbvn { public partial class CrudGrid : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { SqlDataSource1.InsertParameters["Name"].DefaultValue = ((TextBox)GridView1.FooterRow.FindControl("TextBox4")).Text; SqlDataSource1.InsertParameters["Gender"].DefaultValue = ((DropDownList)GridView1.FooterRow.FindControl("DropDownList1")).SelectedValue; SqlDataSource1.InsertParameters["City"].DefaultValue = ((TextBox)GridView1.FooterRow.FindControl("TextBox5")).Text; } protected void SqlDataSource1_Inserted(object sender, SqlDataSourceStatusEventArgs e) { } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)