基于复选框列表项的按钮图像可见性
我有一个带有 9 个按钮图像的复选框列表控件。 我需要它,如果用户选中复选框项目,将显示相应的按钮图像...检查总数 == 3..
例如(对于包含正在检查的权限的所有图像按钮,可见性将设置为true)
所有这些都必须在没有任何按钮点击的情况下完成
<asp:CheckBoxList ID="CheckBoxList1" runat="server"
OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged1"
AutoPostBack="True">
<asp:ListItem Value="Privilege 1">Dining</asp:ListItem>
<asp:ListItem Value="Privilege 2">Travel</asp:ListItem>
<asp:ListItem Value="Privilege 3">Shopping</asp:ListItem>
</asp:CheckBoxList>
<table cellspacing="10">
<tr>
<td>
<asp:ImageButton ID="ImageButton1" runat="server" Height="80px"
Width="120px" ImageUrl="imageurl" ToolTip="image" />
</td>
<td>
<asp:ImageButton ID="ImageButton2" runat="server" Height="80px"
Width="120px" ImageUrl="imageurl" ToolTip="image" />
</td>
<td>
<asp:ImageButton ID="ImageButton3" runat="server" Height="80px"
Width="120px" ImageUrl="imageurlg" ToolTip="image" />
</td>
</tr>
</table>
C# 背后的代码
protected void CheckBoxList1_SelectedIndexChanged1(object sender, EventArgs e)
{
foreach (ListItem listItem in CheckBoxList1.Items)
{
if (listItem.Selected == true)
{
//Just to check which item is being checked
//However, it only returns one item at a time
Label1.Text = ", " + listItem.Text;
}
}
//list of privileges
string[] privilege = { "Privilege 1", "Privilege 2", "Privilege 3", "Privilege 4", "Privilege 5", "Privilege 6", "Privilege 7" };
ImageButton[] Privilege1 = { ImageButton1, ImageButton5, ImageButton6, ImageButton7, ImageButton8 };
........
if (CheckBoxList1.SelectedValue == privilege[i])
{
//set the visibility of respective button images with this privileges to be true
}
}
如何去做呢?请帮忙....
I have a checkboxlist control with 9 button images.
I need it such that if user check on the checkbox item, respective button images will be shown... Total number of checks == 3..
for e.g. (for all images button tat contains the privileges being checked, visibility will be set to true)
ALL THIS MUST BE DONE WITHOUT ANY BUTTON CLICKS
<asp:CheckBoxList ID="CheckBoxList1" runat="server"
OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged1"
AutoPostBack="True">
<asp:ListItem Value="Privilege 1">Dining</asp:ListItem>
<asp:ListItem Value="Privilege 2">Travel</asp:ListItem>
<asp:ListItem Value="Privilege 3">Shopping</asp:ListItem>
</asp:CheckBoxList>
<table cellspacing="10">
<tr>
<td>
<asp:ImageButton ID="ImageButton1" runat="server" Height="80px"
Width="120px" ImageUrl="imageurl" ToolTip="image" />
</td>
<td>
<asp:ImageButton ID="ImageButton2" runat="server" Height="80px"
Width="120px" ImageUrl="imageurl" ToolTip="image" />
</td>
<td>
<asp:ImageButton ID="ImageButton3" runat="server" Height="80px"
Width="120px" ImageUrl="imageurlg" ToolTip="image" />
</td>
</tr>
</table>
Code behind C#
protected void CheckBoxList1_SelectedIndexChanged1(object sender, EventArgs e)
{
foreach (ListItem listItem in CheckBoxList1.Items)
{
if (listItem.Selected == true)
{
//Just to check which item is being checked
//However, it only returns one item at a time
Label1.Text = ", " + listItem.Text;
}
}
//list of privileges
string[] privilege = { "Privilege 1", "Privilege 2", "Privilege 3", "Privilege 4", "Privilege 5", "Privilege 6", "Privilege 7" };
ImageButton[] Privilege1 = { ImageButton1, ImageButton5, ImageButton6, ImageButton7, ImageButton8 };
........
if (CheckBoxList1.SelectedValue == privilege[i])
{
//set the visibility of respective button images with this privileges to be true
}
}
How to go about doing it?? pls helppp....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种方法是:
1) 默认情况下将所有图像按钮的可见性设置为 false(即,由于没有选择复选框项目,它们一开始都是不可见的)。
2) 在代码隐藏中,确保引用 System.Linq。下面的代码根据选择的项目使图像按钮可见(当然将常量放在更中心的位置):
One way is:
1) Set all the Image button's visibility to false by default (i.e. they all start off invisible as no check-box item is selected).
2) In the code-behind make sure you reference System.Linq. The following does the bit of making the image buttons visible depending on which items are selected (place the constants in a more central spot of course):