Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have web page on which i show user notification from database using grid view with sql datasource.

The problem is when user want to update a record, then addional paramters is send to the database table, that is updateby and updatedon.

here is my code.

C#
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ECII(Old)ConnectionString %>" SelectCommand="SELECT * FROM [TblArticles] WHERE (([PublishedBy] = @PublishedBy) AND ([SubcriptionId] = @SubcriptionId)) ORDER BY [ArticleID]" DeleteCommand="DELETE FROM [TblArticles] WHERE [ArticleID] = @ArticleID" InsertCommand="INSERT INTO [TblArticles] ([Title], [Body], [Author], [Categories], [Tags], [PublishedOn], [PublishedBy], [UpdatedOn], [Updatedby], [countlikes], [SubcriptionId]) VALUES (@Title, @Body, @Author, @Categories, @Tags, @PublishedOn, @PublishedBy, @UpdatedOn, @Updatedby, @countlikes, @SubcriptionId)" UpdateCommand="UPDATE [TblArticles] SET [Title] = @Title, [Body] = @Body, [Author] = @Author, [Categories] = @Categories, [Tags] = @Tags, [PublishedOn] = @PublishedOn, [PublishedBy] = @PublishedBy, [UpdatedOn] = @UpdatedOn, [Updatedby] = @Updatedby, [countlikes] = @countlikes, [SubcriptionId] = @SubcriptionId WHERE [ArticleID] = @ArticleID">
        <DeleteParameters>
            <asp:Parameter Name="ArticleID" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="Title" Type="String" />
            <asp:Parameter Name="Body" Type="String" />
            <asp:Parameter Name="Author" Type="String" />
            <asp:Parameter Name="Categories" Type="String" />
            <asp:Parameter Name="Tags" Type="String" />
            <asp:Parameter Name="PublishedOn" Type="DateTime" />
            <asp:Parameter Name="PublishedBy" Type="Int32" />
            <asp:Parameter Name="UpdatedOn" Type="DateTime" />
            <asp:Parameter Name="Updatedby" Type="Int32" />
            <asp:Parameter Name="countlikes" Type="Int64" />
            <asp:Parameter Name="SubcriptionId" Type="Int32" />
        </InsertParameters>
        <SelectParameters>
            <asp:SessionParameter Name="PublishedBy" SessionField="UserID" Type="Int32" />
            <asp:SessionParameter Name="SubcriptionId" SessionField="SubscripID" Type="Int32" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="Title" Type="String" />
            <asp:Parameter Name="Body" Type="String" />
            <asp:Parameter Name="Author" Type="String" />
            <asp:Parameter Name="Categories" Type="String" />
            <asp:Parameter Name="Tags" Type="String" />
            <asp:Parameter Name="PublishedOn" Type="DateTime" />
            <asp:Parameter Name="PublishedBy" Type="Int32" />
            <asp:Parameter Name="UpdatedOn" Type="DateTime" />
            <asp:Parameter Name="Updatedby" Type="Int32" />
            <asp:Parameter Name="countlikes" Type="Int64" />
            <asp:Parameter Name="SubcriptionId" Type="Int32" />
            <asp:Parameter Name="ArticleID" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
<div style="width: 98%; height: 500px; margin: 0 auto; margin-removed 10px; overflow:scroll;">
   
     <asp:GridView ID="GridViewListallarticles" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" DataKeyNames="ArticleID" DataSourceID="SqlDataSource1" ForeColor="Black" GridLines="Vertical" Width="200%" OnSelectedIndexChanged="GridViewListallarticles_SelectedIndexChanged">
         <AlternatingRowStyle BackColor="White" />
         <Columns>
             <%--<asp:BoundField DataField="PublishedBy" HeaderText="PublishedBy" SortExpression="PublishedBy" />--%>
             <%--<asp:BoundField DataField="UpdatedOn" HeaderText="UpdatedOn" SortExpression="UpdatedOn" />--%>
             <%--<asp:BoundField DataField="Updatedby" HeaderText="Updatedby" SortExpression="Updatedby" />--%>
             <%--<asp:BoundField DataField="SubcriptionId" HeaderText="SubcriptionId" SortExpression="SubcriptionId" />--%>
             <asp:CommandField HeaderText="Operations" ShowDeleteButton="True" ShowEditButton="True" ShowHeader="True" />
             <asp:BoundField DataField="ArticleID" HeaderText="ArticleID" InsertVisible="False" ReadOnly="True" SortExpression="ArticleID" />
             <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
             <asp:BoundField DataField="Body" HeaderText="Body" SortExpression="Body" />
             <asp:BoundField DataField="Author" HeaderText="Author" SortExpression="Author" />
             <asp:BoundField DataField="Categories" HeaderText="Categories" SortExpression="Categories" />
             <asp:BoundField DataField="Tags" HeaderText="Tags" SortExpression="Tags" />
             <asp:BoundField DataField="PublishedOn" HeaderText="PublishedOn" SortExpression="PublishedOn" />
             <%--<asp:BoundField DataField="PublishedBy" HeaderText="PublishedBy" SortExpression="PublishedBy" />--%>
             <asp:BoundField DataField="UpdatedOn" HeaderText="UpdatedOn" SortExpression="UpdatedOn" />
             <asp:BoundField DataField="Updatedby" HeaderText="Updatedby" SortExpression="Updatedby" />
             <%--<asp:BoundField DataField="SubcriptionId" HeaderText="SubcriptionId" SortExpression="SubcriptionId" />--%>
             <asp:BoundField DataField="countlikes" HeaderText="countlikes" SortExpression="countlikes" />
         </Columns>
         <FooterStyle BackColor="#CCCC99" />
         <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
         <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
         <RowStyle BackColor="#F7F7DE" />
         <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
         <SortedAscendingCellStyle BackColor="#FBFBF2" />
         <SortedAscendingHeaderStyle BackColor="#848384" />
         <SortedDescendingCellStyle BackColor="#EAEAD3" />
         <SortedDescendingHeaderStyle BackColor="#575357" />
    </asp:GridView>
Posted
Comments
phil.o 28-May-14 20:00pm    
And what is the concrete issue? Does that throw any exception? Does it return any error message?
Remember, we cannot see your screen nor read your mind :)
Please clarify the real issue.
Muhammad Taqi Hassan Bukhari 29-May-14 2:42am    
In the update parameter i have to pass user id and current date on which updated occurs.
CHill60 29-May-14 6:33am    
Could you store the id in Session (Exploring Session in ASP.NET[^]) and just use GetDate for the current date/time

1 solution

Hi Muhammad Taqi Hassan Bukhari

In gridview there are various types of events before and after.


Here you need...

RowUpdating: Is raised before a GridView updates a record, which means that the row's update button has been clicked but before the GridView updates the row.


Follow this link you will get answer.

http://www.c-sharpcorner.com/uploadfile/00c99e/gridview-events-for-beginners/[^]


Let me know if you have any further query.
Please, go through above suggestion.
If its your answer, please mark as solution.
Best of luck for hunting solutions.

Thank you.
Regards,
Manoj Kalla
 
Share this answer
 

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



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