<td> login_type</td>
<td>
<input type="checkbox" name="txt_login_type" id="txt_login_type" value="Crm" runat="server" />Crm
<input type="checkbox" name="txt_login_type1" id="txt_login_type1" value ="Log" runat="server"/>Log
<input type="checkbox" name="txt_login_type2" id="txt_login_type2" value="Innoways" runat="server" />Innoways
<input type="checkbox" name="txt_login_type3" id="txt_login_type3" value="CS" runat="server"/>CS
</td>
<td><input type="checkbox" name="txt_login_type4" value="Account_manager" id="txt_login_type4" runat="server"/>Account_manager
<%--<input name="txt_Logintypes" type="text" value="" maxlength="30" id="txt_Logintypes" class="textboxcontent" runat="server" />--%>
</td>
CS ,Account_manager,Log,Crm
绑定数据checkbox字符 Split返回的字符串进行分割
string[] Array = model.login_type.Split(',');
for (int i = 0; i < Array.Length; i++)
{
if (Array[i].Equals(txt_login_type.Value.Trim()))
{
txt_login_type.Checked = true;
}
if (Array[i].Equals(txt_login_type1.Value.Trim()))
{
txt_login_type1.Checked = true;
}
if (Array[i].Equals(txt_login_type2.Value.Trim()))
{
txt_login_type2.Checked = true;
}
if (Array[i].Equals(txt_login_type3.Value.Trim()))
{
txt_login_type3.Checked = true;
}
if (Array[i].Equals(txt_login_type4.Value.Trim()))
{
txt_login_type4.Checked = true;
}
}
更新保存数据
model.login_type = "";
if (txt_login_type.Checked)
{
model.login_type += txt_login_type.Value.Trim() + ",";
}
if (txt_login_type1.Checked)
{
model.login_type += txt_login_type1.Value.Trim() + ",";
}
if (txt_login_type2.Checked)
{
model.login_type += txt_login_type2.Value.Trim()+",";
}
if (txt_login_type3.Checked)
{
model.login_type += txt_login_type3.Value.Trim()+",";
}
if (txt_login_type4.Checked)
{
model.login_type += txt_login_type4.Value.Trim()+',';
}
Substring 截取字符串
model.login_type = model.login_type.Substring(0, model.login_type.Length - 1);