Jig*_*esh 2 c# asp.net controls repeater
我想启用或禁用'ParticipateBtn',具体取决于EventStartDate.我收到此错误:对象引用未设置为对象的实例.
开始日期:<%#CheckEnability((DateTime)Eval("Event_Start_Date"))%>
<asp:Button runat="server"
ID="ParticipateBtn"
CommandName="Participate"
CommandArgument='<%# Eval("Event_Id") + "|" + Eval("Event_Name") + "|" + Eval("Volume") + "|" + Eval("Tournament_Id") %>'
Text="Participate" />
</ItemTemplate>
<FooterTemplate></FooterTemplate>
<SeparatorTemplate>
<hr style="color:Silver; height:1px;" />
</SeparatorTemplate>
</asp:Repeater>
Run Code Online (Sandbox Code Playgroud)
背后的代码......
//Code behind
protected string CheckEnability(DateTime eventstartdate)
{
if (eventstartdate.Date < DateTime.Now.Date)
{
Button btn = (Button)Repeater1.FindControl("ParticipateBtn");
btn.Enabled = false;
}
return eventstartdate.ToString("yyyy-MM-dd");
}
Run Code Online (Sandbox Code Playgroud)
转发器中的控件在数据绑定之前不存在,然后每个项目的ItemTemplate中的每个控件都存在一次 - 因此,如果绑定到包含3个项目的源,则将有3个ParticipateBtns.在找到之前,您需要知道自己想要哪一个.一旦你这样做,你可以这样做:
myRepeater.Items[1].FindControl("ParticipateBtn");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9546 次 |
| 最近记录: |