繁体   English   中英

转发器控制中的IF条件?

[英]IF condition inside the repeater control?

<asp:CheckBox ID="chkBox1" runat="server" Text="1" />
<asp:CheckBox ID="chkBox2" runat="server" Text="2" />

我有两个复选框,基于选择我需要运行查询并绑定到转发器控件。

在中继控制中:

<asp:Repeater runat="server" ID="Repeater1">
<HeaderTemplate >
<table class="list_table" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<th>1</th>
<th>2</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%=CheckBox1.Checked ? Eval("1") : "" %></td> 
 <td><%=CheckBox2.Checked ? Eval("2") : "" %></td> 

    </tr>
    </ItemTemplate>
    <FooterTemplate>
    </table>
    </FooterTemplate>
    </asp:Repeater>

AVD建议我已经改变了我的编码,如果条件工作正常,但我需要将数据从数据库绑定到转发器控件。

你可以试试,

 <ItemTemplate>
    <tr>
        <td><%=CheckBox1.Checked ? "1" : "" %></td>
        <td><%=CheckBox2.Checked ? "2" : "" %></td>
   </tr>
  </ItemTemplate>

编辑:

@Prince Antony G:如果我选择checkbox1然后运行查询 - 从table1中选择1; 或者如果我选择checkbox2然后运行查询 - 从表2中选择2; 并将数据绑定到我的转发器控件(这两个表都有不同的字段)

不能结合的不同的数据源到DataControl上 ,因为一些结合表达式(列)是不在任一这种情况下,可用的(实测值)。

Page1.aspx标记


<div>
<asp:MultiView ID="MultiView1" runat="server">
    <asp:View ID="View1" runat="server">
        <asp:Repeater ID="Repeater1" runat="server">
        <ItemTemplate>
            <!--Bind the result from first table -->
        </ItemTemplate>
        </asp:Repeater>
    </asp:View>

    <asp:View ID="View2" runat="server">
        <asp:Repeater ID="Repeater2" runat="server">
        <ItemTemplate>
            <!--Bind the result from second table -->
        </ItemTemplate>
        </asp:Repeater>
    </asp:View>
</asp:MultiView>
</div>

Page1.aspx.cs - 代码背后


protected void BindResult(object sender, EventArgs e)
{
    CheckBox check = sender as CheckBox;
    switch (check.Text)
    {
        case "1": 
            /* 
                * 1. Execute - Select * from Table1
                * 2. Bind the DataSource to Repeater1
                */
            /* Shows the first View*/
            MultiView1.ActiveViewIndex = 0;
            break;
        case "2":
            /* 
                * 1. Execute - Select * from Table2
                * 2. Bind the DataSource to Repeater2
                */
            /* Shows the second View*/
            MultiView1.ActiveViewIndex = 1;
            break;
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM