Create a web application to demonstrate use of GridView button column and GridView events

 .Aspx file 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="8c.aspx.cs" 

Inherits="_6A._8c" %> 

<!DOCTYPE html> 

<html xmlns="http://www.w3.org/1999/xhtml"> 

<head runat="server"> 

    <title></title> 

</head> 

<body> 

    <form id="form1" runat="server">         

        <br />    

            <asp:GridView ID="GridView1" runat="server" Height="241px" Width="274px" 

AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" 

BorderStyle="None" BorderWidth="1px" CellPadding="3" DataKeyNames="Id" 

DataSourceID="SqlDataSource1" GridLines="Vertical"> 

                <AlternatingRowStyle BackColor="#DCDCDC" /> 

                <Columns> 

                    <asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" 

SortExpression="Id" /> 

                    <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" /> 

                    <asp:BoundField DataField="STD" HeaderText="STD" SortExpression="STD" /> 

                    <asp:BoundField DataField="Address" HeaderText="Address" 

SortExpression="Address" /> 

                    <asp:BoundField DataField="Phone No." HeaderText="Phone No." 

SortExpression="Phone No." /> 

                    <asp:HyperLinkField DataTextField="Id" /> 

                    <asp:CommandField ButtonType="Button" HeaderText="Edit" 

ShowEditButton="True" ShowHeader="True" /> 

                </Columns> 

                <FooterStyle BackColor="#CCCCCC" ForeColor="Black" /> 

                <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" /> 

                <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" /> 

                <RowStyle BackColor="#EEEEEE" ForeColor="Black" /> 

                <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" /> 

                <SortedAscendingCellStyle BackColor="#F1F1F1" /> 

                <SortedAscendingHeaderStyle BackColor="#0000A9" /> 

                <SortedDescendingCellStyle BackColor="#CAC9C9" /> 

                <SortedDescendingHeaderStyle BackColor="#000065" />           

  </asp:GridView> 

        <br /> 

            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 

ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:connStr 

%>" DeleteCommand="DELETE FROM [Student] WHERE [Id] = @original_Id AND [Name] = @original_Name AND [STD] = @original_STD AND [Address] = @original_Address AND [Phone No.] = @original_column1" InsertCommand="INSERT INTO [Student] ([Id], [Name], 

[STD], [Address], [Phone No.]) VALUES (@Id, @Name, @STD, @Address, @column1)" 

OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM 

[Student]" UpdateCommand="UPDATE [Student] SET [Name] = @Name, [STD] = @STD, 

[Address] = @Address, [Phone No.] = @column1 WHERE [Id] = @original_Id AND [Name] = @original_Name AND [STD] = @original_STD AND [Address] = @original_Address AND 

[Phone No.] = @original_column1"> 

                <DeleteParameters> 

                    <asp:Parameter Name="original_Id" Type="Int32" /> 

                    <asp:Parameter Name="original_Name" Type="String" /> 

                    <asp:Parameter Name="original_STD" Type="String" /> 

                    <asp:Parameter Name="original_Address" Type="String" /> 

                    <asp:Parameter Name="original_Phone No." Type="Decimal" /> 

                </DeleteParameters> 

                <InsertParameters> 

                    <asp:Parameter Name="Id" Type="Int32" /> 

                    <asp:Parameter Name="Name" Type="String" /> 

                    <asp:Parameter Name="STD" Type="String" /> 

                    <asp:Parameter Name="Address" Type="String" /> 

                    <asp:Parameter Name="Phone No." Type="Decimal" /> 

                </InsertParameters> 

                <UpdateParameters> 

                    <asp:Parameter Name="Name" Type="String" /> 

                    <asp:Parameter Name="STD" Type="String" /> 

                    <asp:Parameter Name="Address" Type="String" /> 

                    <asp:Parameter Name="column1" Type="Decimal" /> 

                    <asp:Parameter Name="original_Id" Type="Int32" /> 

                    <asp:Parameter Name="original_Name" Type="String" /> 

                    <asp:Parameter Name="original_STD" Type="String" /> 

                    <asp:Parameter Name="original_Address" Type="String" /> 

                    <asp:Parameter Name="original_Phone No." Type="Decimal" /> 

                </UpdateParameters> 

            </asp:SqlDataSource> 

    </form> 

</body> 

</html> 

Output :-



Post a Comment

0 Comments