如何根据条件使Repeater中的Linkbutton成为标签 [英] How to make Linkbutton in Repeater as Label based on a condition

查看:52
本文介绍了如何根据条件使Repeater中的Linkbutton成为标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,

我使用的Repeater包含5列,分别为Table1,Table1Count,Table2,Table2Count,DifferenceInCount.DifferenceInCount是Linkbutton列,它将在Count1和Count2之间给出区别.
我需要做的是,如果count差为0(零),则我需要使相应的linkbutton作为label字段.有人可以帮我吗...



I am using a Repeater which contains 5 columns which are Table1,Table1Count,Table2,Table2Count,DifferenceInCount.DifferenceInCount is the Linkbutton column where it will give the difference between Count1 and Count2.

What i need to do is if the count Difference is comes as 0(zero),the i need to make the corresponding linkbutton as label field.Can anyone please help me in doing this...

推荐答案

尝试一下,它可能会对您有所帮助:-

在具有linkbutton字段的地方,您只需保留一个标签字段.最初,这两个控件的可见性为false,并且文本与您所拥有的相似.在逐行绑定时,决定是否要显示可见的linkbutton或标签.该逻辑将为您提供帮助,并且Repeater控件的ItemDataBound事件与GridView控件的RowDataBound事件相同,这是可能的.示例代码如下:-

受保护的void Repeater1_ItemDataBound(对象发送方,RepeaterItemEventArgs e)
{
如果(e.Item.ItemType == DataControlRowType.DataRow)
{
LinkBut​​ton lbt =(LinkBut​​ton)e.Item.FindControl("LinkBut​​ton1");
标签lbl =(Label)e.Item.FindControl("Label1");

如果(lbt.Text =="0")
{
lbt.Visible = false;
lbl.Visible = true;
}
其他
{
lbt.Visible = true;
lbl.Visible = false;
}

}
}
Try this one, It may help you :-

Where you have linkbutton field you just keep a label field also. Intially those two controls visibility is false and there text is similar as uyou have. At the time binding row by row decide whether you will make visible linkbutton or label. That logic will help you and that is possible by ItemDataBound event of Repeater control same as RowDataBound event of GridView control. Sample code is given below :-

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == DataControlRowType.DataRow)
{
LinkButton lbt = (LinkButton) e.Item.FindControl("LinkButton1");
Label lbl = (Label)e.Item.FindControl("Label1");

if (lbt.Text == "0")
{
lbt.Visible = false;
lbl.Visible = true;
}
else
{
lbt.Visible = true;
lbl.Visible = false;
}

}
}


这篇关于如何根据条件使Repeater中的Linkbutton成为标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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