从 RowCommand 获取数据
我有一个显示产品版本的网格,并有一些链接按钮,如编辑、删除、预览等。 单击编辑按钮后,我想要获取产品 ID 和版本 ID 并重定向到某个可以编辑产品详细信息的 xyz.aspx 页面。
这是我的网格的外观:
<asp:GridView ID="grdBindVersion" runat="server" AutoGenerateColumns="false"
onrowcommand="grdBindVersion_RowCommand" >
<RowStyle BorderStyle="Solid" BorderWidth="1px" />
<Columns>
<asp:BoundField datafield="HistoryId" HeaderText="Version ID.">
<HeaderStyle CssClass="grid"></HeaderStyle>
</asp:BoundField>
<asp:BoundField datafield="Title" HeaderText="Title">
<HeaderStyle CssClass="grid"></HeaderStyle>
</asp:BoundField>
<asp:TemplateField HeaderText = "Edit">
<ItemTemplate>
<asp:LinkButton ID="Edit" runat="server" CommandArgument='<%# Container.DataItem %>' CommandName ="Add">Edit</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "Delete">
<ItemTemplate>
<asp:LinkButton ID="Delete" runat="server">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "Add Sub Page">
<ItemTemplate>
<asp:LinkButton ID="AddSubPage" runat="server">Add Sub Page</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "Add Rank">
<ItemTemplate>
<asp:LinkButton ID="AddRank" runat="server">Add Rank</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "Approve/DisApprove">
<ItemTemplate>
<asp:LinkButton ID="ApproveStatus" runat="server">Approve/DisApprove</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "Complete">
<ItemTemplate>
<asp:LinkButton ID="Complete" runat="server">Complete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "Preview">
<ItemTemplate>
<asp:LinkButton ID="Preview" runat="server">Preview</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "Comment">
<ItemTemplate>
<asp:LinkButton ID="Comment" runat="server">Comment</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
我正在跟踪 GridView 的 RowCommand
事件中链接按钮的单击。 这里我想获取VersionID和ProductID,然后重定向到另一个页面。 请帮我。 我对编码真的很陌生。 我做了一些谷歌,但没有一个解决方案对我有帮助。
I have a grid which shows product versions and have a few link buttons like edit, delete, preview etc.
On click of the edit button I want to get the Product ID and Version ID and redirect to some xyz.aspx page where the product details can be edited.
Here is how my Grid looks:
<asp:GridView ID="grdBindVersion" runat="server" AutoGenerateColumns="false"
onrowcommand="grdBindVersion_RowCommand" >
<RowStyle BorderStyle="Solid" BorderWidth="1px" />
<Columns>
<asp:BoundField datafield="HistoryId" HeaderText="Version ID.">
<HeaderStyle CssClass="grid"></HeaderStyle>
</asp:BoundField>
<asp:BoundField datafield="Title" HeaderText="Title">
<HeaderStyle CssClass="grid"></HeaderStyle>
</asp:BoundField>
<asp:TemplateField HeaderText = "Edit">
<ItemTemplate>
<asp:LinkButton ID="Edit" runat="server" CommandArgument='<%# Container.DataItem %>' CommandName ="Add">Edit</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "Delete">
<ItemTemplate>
<asp:LinkButton ID="Delete" runat="server">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "Add Sub Page">
<ItemTemplate>
<asp:LinkButton ID="AddSubPage" runat="server">Add Sub Page</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "Add Rank">
<ItemTemplate>
<asp:LinkButton ID="AddRank" runat="server">Add Rank</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "Approve/DisApprove">
<ItemTemplate>
<asp:LinkButton ID="ApproveStatus" runat="server">Approve/DisApprove</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "Complete">
<ItemTemplate>
<asp:LinkButton ID="Complete" runat="server">Complete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "Preview">
<ItemTemplate>
<asp:LinkButton ID="Preview" runat="server">Preview</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "Comment">
<ItemTemplate>
<asp:LinkButton ID="Comment" runat="server">Comment</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I am tracking the clicking on the link button in the RowCommand
event of the GridView.
Here i want to get the VersionID and ProductID and then redirect to another page.
Please help me.
I am really new to coding.
I did a bit of Google but none of the solutions are helping me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以为 Gridview 的 OnRowCommand 分配多个赋值...
并且在代码隐藏中,一一提取参数并将它们分配给会话变量以供以后使用...
You can assign more than one assignment to a Gridview's OnRowCommand ...
And in codebehind, extract the arguments one by one and assign them to session variables for later use ...
将 VersionID 和 ProductID 指定为 GridView 的 DataKeyNames,然后通过查询字符串传递这两个值。
Assign VersionID and ProductID as DataKeyNames of the GridView and then Pass these two values through Query Strings.
您可以通过放置以下代码来获取
gridview_RowCommand
事件的数据:您可以根据您的 GridView 设置
Cells[index]
中的[index]
项目,然后重定向到具有获取的 HistoryId 或 ProductId 的另一个页面。You can get the data on
gridview_RowCommand
event by placing below code:You can set the
[index]
inCells[index]
according to your GridView items, then redirect to another page with that fetched HistoryId or ProductId.