Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My Asp.net file is...

ASP.NET
<%@ 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>


My Code Behind file is

C#
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)
        {
            
        }
    }
}





my sql Table is
EmployeeId int Primary Key Identity(1,1) not null,
Name Varchar(50),
Gender Varchar(20),
City Varchar(50)
Posted
Updated 6-Jan-15 11:55am
v4
Comments
Abeeeeeeeeeeeeeeeeee 6-Jan-15 17:42pm    
Can anyone help plzzz
Blutfaust 6-Jan-15 17:42pm    
And your question is?
Abeeeeeeeeeeeeeeeeee 6-Jan-15 17:45pm    
Insert operation is not working, i dont Know Why
Abeeeeeeeeeeeeeeeeee 6-Jan-15 17:51pm    
my Table Structure is


EmployeeId int Primary Key Identity(1,1) not null,
Name Varchar(50),
Gender Varchar(20),
City Varchar(50)
Abeeeeeeeeeeeeeeeeee 6-Jan-15 17:50pm    
Itz Entering the Event Handling Routine And the Proper Values Are are populating when i debug the App.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900