如何在Datalist中获取Clicked Link按钮的文本 [英] How to get Text of Clicked Link Button in Datalist

查看:72
本文介绍了如何在Datalist中获取Clicked Link按钮的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Datalist显示链接按钮,文本从数据库中获取。

我想要的是,当我点击任何链接按钮时,我想得到我点击的链接按钮的文本。



尽可能提供一个例子

I Have Datalist which display link buttons with text fetch from database .
what i want is , when i click on any link button , i want to get the text of that link button which i clicked.

Do provide a example if possible

推荐答案





在链接按钮的单击事件中,您将第一个参数作为对象(发件人)。您需要将该对象输入到LinkBut​​ton中,然后才能获得该按钮的文本。



这对你有用

谢谢

Amit
Hi,

In click event of your link button you have first argument as object(Sender). You need to type cast that object into LinkButton and then you can get text of that button.

That will work for you
Thanks
Amit


您可以订阅DataList_ItemCommand事件。

You can subscribe to DataList_ItemCommand event.
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
    LinkButton lb = source as LinkButton;
    if(lb != null) 
    {
        string clickedText = lb.Text;
    }
}


string sd;
 sd = ((LinkButton)sender).Text;

 Response.Redirect("Page.aspx?id=" + sd);





我收到所选链接按钮的文字。

解决了



I get the text of selected link button.
Solved


这篇关于如何在Datalist中获取Clicked Link按钮的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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