我要在Repeater中实现根据当前行某列的值来判断当前行一个LinkButton要不要显示出来。
现在我用Repeater1_ItemDataBound 事件 <asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound" >
..
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        Response.Write("测试~");
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
            Response.Write(((LinkButton)e.Item.FindControl("btncf")).Text);
        }
    }在事件那边设断点根本都没被执行到~
为什么不会被执行?页面没打印文本出来。(Repeater数据绑定没有问题)
Repeater1_ItemDataBound 事件为什么不会被调用?还是我方法用错了。。请各位帮帮忙~
我以前好像这么做是可以的,不知道为什么现在不行了~

解决方案 »

  1.   

    如果实在不行,就写个函数来为示或隐藏吧
    <%#Show(Eval("??"))%> protected string Show(object strInput)
    {
     if(strInput.ToString()=="??")
    {...}
    else
    {..}
    }
      

  2.   

    是一个按钮,这个方法我也知道。关键是你..的那些怎么写?
    按钮怎么获取?比如每行都有一个
    <asp:LinkButton runat="Server" CommandName='<%#((BeanBusiness)Container.DataItem).ID %>' Enabled="false" OnCommand="btn_cf" ID="btncf">重发</asp:LinkButton>
    怎么根据某个列隐藏这个按钮
      

  3.   

    <asp:repeater id="Repeater1" Runat="server">
    <ItemTemplate>
        <asp:LinkButton ID="LinkButton1" runat="server" CommandName="XXX" Visible='<%# Eval("YourField").ToString() == "YourText" ? true : false %>'>XXX</asp:LinkButton>
    </ItemTemplate>
    </asp:repeater>
      

  4.   


    <asp:LinkButton ID="lbtn" runat="server" Enabled='<%#Eval("fieldName").ToString()=="true"?true:false %>'></asp:LinkButton>类似这样
      

  5.   

    sorry ~ 应该是Visible
    <asp:LinkButton ID="lbtn" runat="server" Visible='<%#Eval("fieldName").ToString()=="true"?true:false %>'></asp:LinkButton>
      

  6.   

    获取列索引(基于0) <%# Container.ItemIndex %>
      

  7.   

    其实用函数是最好的:
    <%#Show(Eval("??"))%>protected string Show(object strInput)
    {
    if(strInput.ToString()=="??")
    {...}
    else
    {..}
    } 如果有三种以上的情况,<asp:LinkButton ID="lbtn" runat="server" Visible='<%#Eval("fieldName").ToString()=="true"?true:false %>'></asp:LinkButton>
    就显得有心没有力。