GridView内部的LinkBut​​ton可见性 [英] LinkButton Inside GridView Visibility

查看:56
本文介绍了GridView内部的LinkBut​​ton可见性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在gridview内有linkbutton
我想更改linkbutton的可见性取决于数据库返回的值
所以我创建了

i have linkbutton inside gridview
i want to change linkbutton visibility depende on value return from database
so i create that

<asp:LinkButton ID="Lnk" runat="server"  CommandArgument='<%# Bind("ArrivalMasterID") %>' Text="Cost" <big>Visible='<%# Bind("IsNewRow") %>'</big> /> 


但我有一个问题
我将linkbutton的可见性更改为isnewrow值
表示如果isbewrowvalue = ture,则为linkbutton.visible = false
我需要使用html代码而不是c#codey
任何帮助


but i have one problem
i wnat linkbutton visibility to be reverse to isnewrow value
mean if isbewrowvalue=ture then linkbutton.visible=false
i need to do it from html code not from c# codey
any help

推荐答案

关于gridview rowdatabound事件,您可以添加以下代码,保持<%#Bind(!"IsNewRow")%>这是gridview的datakey字段.

bool Isnewrow
如果(e.Row.RowType == DataControlRowType.DataRow)
{

Isnewrow = Convert.ToBool(gridview.DataKeys [e.Row.RowIndex] .Values [0]);

LinkBut​​ton lnkBut​​ton =(LinkBut​​ton)e.Row.FindControl("lnkViewDetails");
if(Isnewrow)
{
lnkbutton.visible = true;
}
其他
lnkbutton.visible = false;


将Isnewrow字段添加为gridview的数据键


< asp:GridView ID ="gridview1" AllowPaging ="true"
AutoGenerateColumns ="false" DataKeyNames ="Isnewrow"
runat ="server" ShowFooter ="true"
onrowdatabound ="grdCustomerFeedback_OnRowDataBound">
on gridview rowdatabound event you can add following code keep your <%# Bind(!"IsNewRow") %> which is as datakey field of gridview.

bool Isnewrow
if (e.Row.RowType == DataControlRowType.DataRow)
{

Isnewrow= Convert.ToBool(gridview.DataKeys[e.Row.RowIndex].Values[0]);

LinkButton lnkButton = (LinkButton)e.Row.FindControl("lnkViewDetails");
if(Isnewrow)
{
lnkbutton.visible=true;
}
else
lnkbutton.visible=false;


To add Isnewrow field as datakey of gridview


<asp:GridView ID="gridview1" AllowPaging="true"
AutoGenerateColumns="false" DataKeyNames="Isnewrow "
runat="server" ShowFooter="true"
onrowdatabound="grdCustomerFeedback_OnRowDataBound">


尝试类似的事情
Try something like this
if (e.Row.RowType == DataControlRowType.DataRow)
                  {
YourClass object = (YourClass)e.Row.DataItem;
 LinkButton lnkbtn= (LinkButton)e.Row.FindControl("Lnk");
  lnkbtn.Visible = !Convert.ToBoolean(object.Value);   
}           



好吧,这将根据您当前的实现为您完成工作.使用不(!)运算符



Well, This will do the job for you as per your current implementation. use a Not ( ! ) Operator

<br />
Visible=<%# !(Convert.ToBoolean(Eval("IsNewRow"))) %>


让我知道它是否有效.


Let me know if it work.


这篇关于GridView内部的LinkBut​​ton可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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