一定要女程爆照才有人进来吗!!!复选框选中选中选中!!!
各位蜀黍们!!!
是酱紫的
有个areaid字段 存贮多选框中选中的省份ID 就像酱紫!用逗号分隔!!10000081,10000118,10000157,10000201,10000241,10003568
但是!!重点是!如果用户点进来更新的话!!!!他之前选中的!!要在复选框上默认选中啊!!!肿么搞!!!
[解决办法]
page_load的时候,把10000081,10000118,10000157,10000201,10000241,10003568拆开,根据ID找到对应省份,Selected="True"
[解决办法]
创建所有checkbox的时候name为 10000081 也就是你的省代号
string[] sArray = CurrAdmin.AreaID.Split(',');
foreach (string i in sArray)
{
CheckBox cbx = (CheckBox)this.Controls.Find(i,false)[0];
cbx.Checked = true;
}
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
<asp:ListItem Text="上海" Value="10010"></asp:ListItem>
<asp:ListItem Text="北京" Value="10011"></asp:ListItem>
</asp:CheckBoxList>
string str = modelproject.data;
string[] strs = str.Split(',');
SetCheckBoxList(this.cbData, strs);
/// <summary>
/// 使CheckBoxList中指定项选中
/// </summary>
/// <param name="chk">CheckBoxList的id</param>
/// <param name="arrayValue">CheckBoxList的值的数组</param>
public void SetCheckBoxList(System.Web.UI.WebControls.CheckBoxList chk, string[] arrayValue)
{
if (arrayValue.Length > 0)
{
for (int i = 0; i < arrayValue.Length; i++)
{
foreach (ListItem item in chk.Items)
{
if (item.Value == arrayValue[i].ToString())
{
item.Selected = true;
}
}
}
}
}