如何将HyperLink放入网格并在服务器中访问它 [英] how To Put HyperLink In Grid and access it in Server

查看:75
本文介绍了如何将HyperLink放入网格并在服务器中访问它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

网格视图中的问题
我将链接"或超链接"放在网格中,并且希望在服务器代码中访问它,但它没有出现
而且无法访问!
为什么?

Problem In Grid View
i put Link Or HyperLink In Grid and i Want Access It In server Code but it not come
and it not accessable!
why?

推荐答案

下面说明了如何在网格中访问linkbutton,并在服务器端的linkbutton中添加了一些额外的数据.

试试:
以下将ItemName绑定到LinkButtonCommandArgument.
Following illustrates access of linkbutton in grid with some extra data in linkbutton on server side.

Try:
Following binds the ItemName to the CommandArgument of the LinkButton.
<asp:LinkButton ID="LinkButton1" runat="server" Text="Add to cart"

   OnClick="LinkButton1_Click" CommandArgument='<%# Eval("ItemName") %>' />



然后,您可以在后面的代码中像这样检索它:



You can then retrieve it like this in the code behind:

protected void LinkButton1_Click(object sender, EventArgs e)
{
  LinkButton myButton = sender as LinkButton;
  if (myButton != null)
  {
     string title = myButton.CommandArgument;
     // use this title now to set as a text for your label.
     // Use below for rowIndex
     // CommandArgument='<%# Container.DataItemIndex %>'
   }
}


发送方持有对触发事件处理程序的LinkButton的引用.
您可以将对象转换为LinkButton,然后检索其CommandArgument并将其转换为字符串.


The sender holds a reference to the LinkButton that triggered the event handler.
You can cast the object into a LinkButton and then retrieve its CommandArgument and cast that into string.


这篇关于如何将HyperLink放入网格并在服务器中访问它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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