从 RowCommand 获取数据

发布于 2024-11-07 20:25:47 字数 3460 浏览 1 评论 0原文

我有一个显示产品版本的网格,并有一些链接按钮,如编辑、删除、预览等。 单击编辑按钮后,我想要获取产品 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

暗地喜欢 2024-11-14 20:25:47
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "Edit")
    {
        GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
        // row contains current Clicked Gridview Row
        String VersionId = row.Cells[CellIndex].Text;
        .............
        .............
        //e.CommandArgument  -- this return Data Key Value
    }
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "Edit")
    {
        GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
        // row contains current Clicked Gridview Row
        String VersionId = row.Cells[CellIndex].Text;
        .............
        .............
        //e.CommandArgument  -- this return Data Key Value
    }
}
此生挚爱伱 2024-11-14 20:25:47

您可以为 Gridview 的 OnRowCommand 分配多个赋值...

        <asp:TemplateField HeaderText="Feedback Form">
            <ItemTemplate>
                <asp:LinkButton runat="server" ID="lnkFB" Enabled="true" Text="CREATE"
                        CommandArgument='<%# Eval("ApprenticeshipID") + ";" + Eval("OrganisationID") + ";" + Eval("StudentID") %>' CommandName="btnFB" 
            </ItemTemplate>
            <HeaderStyle HorizontalAlign="Center" />
            <ItemStyle HorizontalAlign="Center" />
        </asp:TemplateField>

并且在代码隐藏中,一一提取参数并将它们分配给会话变量以供以后使用...

string[] arg = new string[2]; //say up to 3 arguments (ie: 0,1,2)
arg = e.CommandArgument.ToString().Split(';');
Session["ApprenticeshipID"] = arg[0]; //I only need first argument
GenerateFeedbackForm(Session["ApprenticeshipID"].ToString());

You can assign more than one assignment to a Gridview's OnRowCommand ...

        <asp:TemplateField HeaderText="Feedback Form">
            <ItemTemplate>
                <asp:LinkButton runat="server" ID="lnkFB" Enabled="true" Text="CREATE"
                        CommandArgument='<%# Eval("ApprenticeshipID") + ";" + Eval("OrganisationID") + ";" + Eval("StudentID") %>' CommandName="btnFB" 
            </ItemTemplate>
            <HeaderStyle HorizontalAlign="Center" />
            <ItemStyle HorizontalAlign="Center" />
        </asp:TemplateField>

And in codebehind, extract the arguments one by one and assign them to session variables for later use ...

string[] arg = new string[2]; //say up to 3 arguments (ie: 0,1,2)
arg = e.CommandArgument.ToString().Split(';');
Session["ApprenticeshipID"] = arg[0]; //I only need first argument
GenerateFeedbackForm(Session["ApprenticeshipID"].ToString());
尾戒 2024-11-14 20:25:47

将 VersionID 和 ProductID 指定为 GridView 的 DataKeyNames,然后通过查询字符串传递这两个值。

Assign VersionID and ProductID as DataKeyNames of the GridView and then Pass these two values through Query Strings.

心是晴朗的。 2024-11-14 20:25:47

您可以通过放置以下代码来获取 gridview_RowCommand 事件的数据:

 Int32 HistoryId = Convert.ToInt32(e.Row.Cells[0].Text.ToString());

您可以根据您的 GridView 设置 Cells[index] 中的 [index]项目,然后重定向到具有获取的 HistoryId 或 ProductId 的另一个页面。

You can get the data on gridview_RowCommand event by placing below code:

 Int32 HistoryId = Convert.ToInt32(e.Row.Cells[0].Text.ToString());

You can set the [index] in Cells[index] according to your GridView items, then redirect to another page with that fetched HistoryId or ProductId.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文