中继器控件内的 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 :如果我选择复选框 1,则运行查询 - 从表 1 中选择1;或者如果我选择复选框 2 然后运行查询 - 从表 2 中选择 2;并将数据绑定到我的中继器控件中(这两个表都有不同的字段(
不能将不同的数据源绑定到 DataControl,因为某些绑定表达式(列(在这两种情况下都不可用(找到(。
页1.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>
第 1 页.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;
}
}
相关文章:
- 我已经创建了一个jquery转盘,并使用if条件来运行和停止转盘
- 带有 AJAX 响应或 AJAX 响应的 IF 条件.响应.Text 不起作用
- if条件中的递归混淆,JS如何解释“;真/假”;条件
- 如何在ejs模板中使用if条件
- for循环与if条件
- 中继器控件内的 IF 条件
- 比较IF条件下的两个javascript数值
- 如何在 javascript 中使用 document.getelementbyname 中的 if 条件
- 是否可以将鼠标悬停(evt)与if条件结合使用
- 当if条件被添加到循环中时,Javascript函数将停止工作
- 我的if条件的执行
- 为什么它没有进入 if 条件
- else-if条件在js渲染模板中
- 在模态中使用 e.target 的复杂 if 条件.js
- 达到IF条件后停止功能
- 如何使用流星模板上的if条件
- javascript setinterval使用if条件显示图像
- Check IF条件返回false,但IF中的语句仍然可以在JavaScript中工作
- if条件如何在javascript中计算其值
- for循环中嵌套if条件的setTimeout