0

我想隐藏中继器控件最后一行的下拉菜单。我使用了以下代码,但无法隐藏下拉菜单。

 <asp:Repeater ID="RpFilter" runat="server" OnItemDataBound="rpFilter_DataBound">
<HeaderTemplate>
<table style=" border:1px solid #df5015; width:500px" cellpadding="0">
<tr style="background-color:#df5015; color:White">
<td colspan="2">
<b>Advanced Filter</b>
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<table style="background-color:#EBEFF0;border-top:1px dotted #df5015; width:500px" >
<tr>
<td>
<asp:Label ID="lblField" runat="server" Text='<%# Eval("COLUMN_NAME")%>' Font-Bold="true"/>
</td>
<td>
<asp:DropDownList ID="ddlCondition" runat="server">
<asp:ListItem Text="Equals" Value="Equals"></asp:ListItem>
<asp:ListItem Text="Not Equals" Value="Not Equals"></asp:ListItem>
<asp:ListItem Text="Less Than" Value="Less Than"></asp:ListItem>
<asp:ListItem Text="Greater Than" Value="Greater Than"></asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:TextBox ID="txtsearch" runat="server"></asp:TextBox>
</td>
<td>
<asp:DropDownList ID="ddlOperator" runat="server">
<asp:ListItem Text="AND" Value="AND"></asp:ListItem>
<asp:ListItem Text="OR" Value="OR"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="btnClose" runat="server" Text="Close"                
 class="fancybox-close" OnClick="btnCloseMsg_Click" />
<asp:Button ID="btnSearch" runat="server" Text="Search"                
 class="fancybox-close" OnClick="btnSearch_Click" />

</FooterTemplate>
</asp:Repeater>

后面的代码:

     protected void rpFilter_DataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || 
        e.Item.ItemType == ListItemType.AlternatingItem)

        {
            if (e.Item.ItemIndex == RpFilter.Items.Count - 1)
            {
                DropDownList Operator = (DropDownList)e.Item.FindControl("ddlOperator");
                Operator.Visible = false;
            }
        }
   }
4

3 回答 3

0

您需要在数据绑定后执行此操作。在rpFilter_DataBound事件中,当前行始终是最后一行,在那个时刻

于 2012-08-07T08:15:03.963 回答
0

我认为没有必要使用条件

 if (e.Item.ItemIndex == RpFilter.Items.Count - 1)

你的代码应该是

protected void rpFilter_DataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || 
    e.Item.ItemType == ListItemType.AlternatingItem)

    {

            DropDownList Operator = (DropDownList)e.Item.FindControl("ddlOperator");
            Operator.Visible = false;

    }

}

于 2012-08-07T08:23:27.763 回答
0

我通过在 prerender 事件中使用它来解决它

protected void rpFilter_PreRender(object sender, EventArgs e)
{
    Repeater RpFilter = (Repeater)FindControl("RpFilter");

    foreach (RepeaterItem item in RpFilter.Items)
    {
        if (RpFilter.Items.Count > 0)
        {
            RepeaterItem rptItem = RpFilter.Items[RpFilter.Items.Count - 1];

            DropDownList ddlOperator = (DropDownList)rptItem.FindControl("ddlOperator");
            ddlOperator.Visible = false;
        }
    }  

}

谢谢大家

于 2012-08-07T09:05:35.973 回答