Friday, 9 December 2011

Asp.net GriView Control and Asp.net SqlDataSourec Control used with Delete and Insert Options


<body>
    <form id="form1" runat="server">
    <div>
     <asp:GridView ID="TahirGrid" runat="server" AllowPaging="True" AllowSorting="True"
            AutoGenerateColumns="False" DataKeyNames="pk"
            DataSourceID="TahirDataSource"
            EmptyDataText="There are no data records to display.">
         
   <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="Job_Title"    HeaderText="Job_Title"  SortExpression="Job_Title" />
                <asp:BoundField DataField="Job_Description" HeaderText="Job_Description"   SortExpression="Job_Description"  />
<asp:BoundField DataField="Experience_Required" HeaderText="Exprience_Required"   SortExpression="Exprience_Required"  />
<asp:BoundField DataField="Skills_Required" HeaderText="Skills_Required"   SortExpression="Skills_Required"  />
<asp:BoundField DataField="pk" HeaderText="ppk"   SortExpression="ppk"  />
    </Columns>

        </asp:GridView>
       
        <asp:SqlDataSource ID="ExencoDataSource" runat="server"
         ConnectionString="server=mssql2008-1;database=salmanexenco_2;user id=tahir; password=khalid"

            DeleteCommand="DELETE FROM [JobTable] WHERE [pk]=@pk"
            InsertCommand="INSERT INTO [JobTable] ([Job_Title],[Job_Description], [Experience_Required],[Skills_Required],[pk]) VALUES (@Job_Title,@Job_Description, @Experience_Required,@Skills_Required,@pk)"
            SelectCommand="SELECT [Job_Title],[Job_Description],[Experience_Required],[Skills_Required],[pk] FROM [JobTable]"
            UpdateCommand="UPDATE [JobTable] SET [Job_Title]=@Job_Title,[Job_Description]=@Job_Description,[Experience_Required]=@Experience_Required,[Skills_Required]=@Skills_Required WHERE [pk] = @pk">
            <InsertParameters>
                <asp:Parameter Name="Job_Title" Type="String"  />
                <asp:Parameter Name="Job_Description" Type="String"/>
<asp:Parameter Name="Experience_Required" Type="String"  />
                <asp:Parameter Name="Skills_Required" Type="String"/>
<asp:Parameter Name="pk" Type="Int32"/>
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="Job_Title" Type="String"  />
                <asp:Parameter Name="Job_Description" Type="String"/>
<asp:Parameter Name="Experience_Required" Type="String"  />
                <asp:Parameter Name="Skills_Required" Type="String"/>
<asp:Parameter Name="pk" Type="Int32" />
            </UpdateParameters>
            <DeleteParameters>
                <asp:Parameter Name="pk" Type="Int32" />
            </DeleteParameters>
        </asp:SqlDataSource>
   
    </div>
    </form>
</body>

No comments:

Post a Comment