如何在gridview之外获取命令参数值。 [英] How to get the command argument value outside the gridview.

查看:66
本文介绍了如何在gridview之外获取命令参数值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个gridview。在这里我有一个名为edit的链接。当我们点击编辑它通过Command Argument获取特定的行ID。但是我想要在Gridview eventargs之外的命令参数值。



我尝试了什么:



我试过Viewstate和session但我不能得到值。

I have a gridview.In this I have a linkbuton called "edit".When we click the Edit its getting the particular row ID through Command Argument.But i want the command argument value outside the Gridview eventargs .

What I have tried:

I tried Viewstate and session but i cant to get the values.

推荐答案

<asp:GridView ID="MyGridView" runat="server">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:LinkButton ID="MyLinkButton" CommandArgument="A" CommandName="Link" runat="server">Click</asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>







MyGridView.DataSource = data;
MyGridView.DataBind();

foreach (GridViewRow row in MyGridView.Rows)
{
    // The linkbutton is in the first cell in my example
    TableCell cell = row.Cells[0];

    LinkButton MyLinkButton = (LinkButton)cell.FindControl("MyLinkButton");

    System.Diagnostics.Debug.WriteLine(MyLinkButton.CommandName);
    System.Diagnostics.Debug.WriteLine(MyLinkButton.CommandArgument);
}


这篇关于如何在gridview之外获取命令参数值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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