在网格视图中使用update命令发送更多参数 [英] Send more parameter with update command in grid view

查看:74
本文介绍了在网格视图中使用update命令发送更多参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,我在网页上使用带有sql数据源的网格视图显示来自数据库的用户通知。



问题是用户想要更新记录,然后addions paramters被发送到数据库表,即updateby和updatedon。



这是我的代码。



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.

<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>

推荐答案

ConnectionStrings:ECII(旧)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],[标签],[PublishedOn],[PublishedBy],[UpdatedOn],[Updatedby],[countlikes],[SubcriptionId])VALUES(@Title,@ Body,@ Author,@ Category,@ Tags,@ PostlishedOn,@ PububyBy, @UpdatedOn,@ Updatedby,@ countlikes,@ SubscriptionId) UpdateCommand = UPDATE [TblArticles] SET [Title] = @Title,[Body] = @ Body,[作者] = @Author,[类别] = @Categories,[TagsOn] = @Tags,[PublishedBy] = @PublishedBy,[UpdatedOn] = @UpdatedOn,[Updatedby] = @Updatedby,[countlikes] = @countlikes,[SubcriptionId ] = @SubcriptionId WHERE [ArticleID] = @ArticleID >
< DeleteParameters>
< asp:参数名称= ArticleID Type = Int32 />
< / DeleteParameters >
< InsertParameters>
< asp:参数名称= 标题类型= String />
< asp:参数名称= 正文类型= String />
< asp:参数名称= 作者类型= String />
< asp:参数名称= 类别类型= String />
< asp:参数名称= 标签 Type = String />
< asp:参数名称= PublishedOn Type = DateTime />
< asp:参数名称= PublishedBy Type = Int32 />
< asp:参数名称= UpdatedOn Type = DateTime />
< asp:参数名称= 更新为 Type = Int32 />
< asp:参数名称= countlikes Type = Int64 />
< asp:参数名称= SubcriptionId Type = Int32 />
< / InsertParameters >
< SelectParameters>
< asp:SessionParameter Name = PublishedBy SessionField = UserID Type = Int32 />
< asp:SessionParameter Name = SubcriptionId SessionField = SubscripID Type = Int32 />
< / SelectParameters >
< UpdateParameters>
< asp:参数名称= 标题类型= String />
< asp:参数名称= 正文类型= String />
< asp:参数名称= 作者类型= String />
< asp:参数名称= 类别类型= String />
< asp:参数名称= 标签 Type = String />
< asp:参数名称= PublishedOn Type = DateTime />
< asp:参数名称= PublishedBy Type = Int32 />
< asp:参数名称= UpdatedOn Type = DateTime />
< asp:参数名称= 更新为 Type = Int32 />
< asp:参数名称= countlikes Type = Int64 />
< asp:参数名称= SubcriptionId Type = Int32 />
< asp:参数名称= ArticleID Type = Int32 />
< / UpdateParameters >
< / asp:SqlDataSource >
< div style = width:98%; height:500px; margin :0 auto; margin-removed 10px; overflow:scroll; >

< asp:GridView ID = < span class =code-string> GridViewListallarticles runat = server AutoGenerateColumns = False BackColor = 白色 BorderColor = #DEDFDE BorderStyle = BorderWidth = 1px CellPadding = 4 DataKeyNames = ArticleID DataSourceID = SqlDataSource1 ForeColor = 黑色 GridLines = Vertical Width = 200% OnSelectedIndexChanged = GridViewListallarticles_SelectedIndexChanged >
< AlternatingRowStyle BackColor = White />
< Columns>
<% - < asp:BoundField DataField = PublishedBy HeaderText = < span class =code-string> PublishedBy SortExpression = PublishedBy /> - %>
<% - < asp:BoundField DataField = UpdatedOn HeaderText = < span class =code-string> UpdatedOn SortExpression = UpdatedOn /> ; - %>
<% - < asp:BoundField DataField = 更新 HeaderText = 更新 SortExpression = 更新 /> - %>
< ;% - < asp:BoundField DataField = SubcriptionId HeaderText = SubcriptionId SortExpression = SubcriptionId /> - %>
< asp:CommandField HeaderText = 操作 ShowDeleteButton = True ShowEditButton = True ShowHeader = True />
< asp:BoundField DataField = ArticleID HeaderText = ArticleID InsertVisible = False ReadOnly = True SortExpression = ArticleID />
< asp:BoundField DataField = 标题 HeaderText = 标题 SortExpression = 标题 />
< asp:BoundField DataField = Body HeaderText = 正文 SortExpression = 身体 />
< asp:BoundField DataField = 作者 HeaderText = 作者 SortExpression = 作者 />
< asp:BoundField DataField = 类别 HeaderText = 类别 SortExpression = 类别 />
<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>
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>


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 furt her 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
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


这篇关于在网格视图中使用update命令发送更多参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆