如何通过使用GridView中的链接按钮事件获取值 [英] how to get the value by using link button event in GridView

查看:70
本文介绍了如何通过使用GridView中的链接按钮事件获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我有GridView&我将CategoryID与DataKeyNames绑定了.
DataKeyNames =类别ID"

我的GridView中有链接按钮.

当我单击该链接按钮时,我需要获取该行的CategoryID.

我需要为此链接按钮编写哪个事件以及如何执行?

Dear All,

I have GridView & i binded CategoryID with DataKeyNames.
DataKeyNames="CategoryID"

I have link button in my GridView.

When i click that link button i need to get that row CategoryID.

Which event i need to write for this link button & how to do this?

推荐答案

hi,
您可以为链接按钮定义CommandArgument和CommandName,例如:

you can define CommandArgument and CommandName for your link button,For example :
<ItemTemplate>
<asp:LinkButton ID="user" runat="server" CssClass="grid_Link" CommandArgument='<%# Eval("idHuman") %>' CommandName="Edit" Text='<%# Eval("userName") %>'></asp:LinkButton>
</ItemTemplate>



并在gridview的RowCommand事件中获取commandArgument:



and in RowCommand event of gridview get commandArgument :

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        switch (e.CommandName)
        {
            case "Edit":
                {
                    string userName = e.CommandArgument.ToString();
                }
                break;
        }
    }



您需要使用LinkBut​​ton的LinkBut​​ton_Command.只需将LinkBut​​ton的CommandName设置为某些内容(例如"Select"),然后将CategoryId绑定到它的CommandArgument.然后,在LinkBut​​ton_Command上,可以获得单击了LinkBut​​ton的那一行的CategoryId.

希望对您有帮助,
干杯.
Hi,
You need to use LinkButton_Command of your LinkButton. Just set the CommandName of the LinkButton to something(for instance ''Select'') and Bind the CategoryId to it''s CommandArgument. Then, on LinkButton_Command you can get the CategoryId of that row which it''s LinkButton is clicked.

I hope it helps,
Cheers.


在网格视图的行命令"事件中尝试使用此方法

Try this in Row Command event of grid view

int rowindex = Convert.ToInt32(e.CommandArgument);
int MRLID = Convert.ToInt32(gvMRLSearch.DataKeys[rowindex].Value); //gvMRLSearch is gridview name


这篇关于如何通过使用GridView中的链接按钮事件获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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