如何在运行时禁用Grid View中使用的锚点 [英] How to diable the anchor used in Grid View at runtime

查看:85
本文介绍了如何在运行时禁用Grid View中使用的锚点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用C#在asp.net中使用GridView,其中将锚点放置在图像的第一列中,因此一旦单击图像,它将转到另一个页面.
我需要对此进行验证,如果未登录的用户有权编辑锚点,则应禁用锚点,即应该发生点击事件,

我尝试过这种方法来获取行数据绑定中锚点的属性,但这不起作用.

我的休假代码

Hi,

I am using GridView in asp.net using C# in which placed an anchor in the first column in with an image so once clicked the image it goes to the other pag.
I need to validate this, if not the logged in uses has access to edit the anchor, anchor should be disabled that is click event should be happen,

I tried this way to get the property of the anchor in row databound, but this is not working.

My code as fallows

if (e.Row.RowType == DataControlRowType.DataRow)
{
//Condition for access
HtmlAnchor hreft = (HtmlAnchor)e.Row.FindControl("btnedit");
hreft .Disabled = true;







<a  href='<%# Eval("Testing", "testing.aspx?ID={0}") %>' id="btnedit">
                                            <img src="Images/edit.png" alt="View" border="0px" /></a>



在调试时,我只是得到空值,

谁能找到我哪里出了问题...

在此先谢谢您



At debugging I am just getting the null value,

Can any one find me where I went wrong...

Thanks in advance

推荐答案

您可以动态分配href属性.如下所示.

You can assign the href attribute dynamically. Something like below.

if (e.Row.RowType == DataControlRowType.DataRow)
{
//Condition for access
HtmlAnchor hreft = (HtmlAnchor)e.Row.FindControl("btnedit");
if(IsUserLogin)
{
hreft.HRef = assign URL
}
else
{
hreft.HRef = "javascript:void(0);";
}
}




希望对您有所帮助.




Hope it helps.


这篇关于如何在运行时禁用Grid View中使用的锚点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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