例如:心肌梗死部位:□前壁 □侧壁 □下壁 □后壁 □右室 其他____
前台: <asp:CheckBoxList ID="CheckBoxList1" runat="server" RepeatDirection="Horizontal" RepeatColumns="0" RepeatLayout="Flow"></asp:CheckBoxList>
<asp:TextBox ID="Teothers" runat="server" Width="100" MaxLength="200" CssClass="TextBoxLine" Visible="false"></asp:TextBox>
后台给控件添加选项:this.Teothers.Text = AddCheckBoxListItems(this.CheckBoxList1, shuzu, "");
提交:
string tj= GetCheckBoxListValue(this.CheckBoxList1, this.Teothers);
model.xinjigengsi = Common.regVerify.str(tj);
查看赋值:
string ck= FilterNullToEmpty(model.xinjigengsi);this.Teothers.Text = AddCheckBoxListItems(this.CheckBoxList1, shuju, ck);
所需方法
方法1:public static string[] shuzu= {"前壁","侧壁","下壁","后壁","右室"};
方法2:
public static string AddCheckBoxListItems(ListControl cbl, string[] arrResource, string strAnalysis)
{
string strRtn = "";
string str = FilterNullToEmpty(strAnalysis);
int pos = str.LastIndexOf("|");
if (pos >= 0)
{
strRtn = str.Substring(pos + 1);
str = str.Substring(0, pos);
}
string[] str_array = str.Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
int j = 0;
for (int i = 0; i < arrResource.Length; i++)
{
string tmp = arrResource[i].Trim();
if (string.IsNullOrEmpty(tmp))
continue;
ListItem li = new ListItem(tmp, (i + 1).ToString());
if (j < str_array.Length && (i + 1).ToString() == str_array[j])
{
li.Selected = true;
j++;
}
cbl.Items.Add(li);
}
return strRtn;
}
方法3:
public static string str(string str)
{
if (string.IsNullOrEmpty(str))
return "";
str = str.Replace("&", "&");
str = str.Replace("<", "<");
str = str.Replace(">", ">");
str = str.Replace("'", "''");
str = str.Replace("*", "");
str = str.Replace("\r\n", "<br/>");
str = str.Replace("\n", "<br/>");
str = str.Replace("select", "");
str = str.Replace("insert", "");
str = str.Replace("update", "");
str = str.Replace("delete", "");
str = str.Replace("create", "");
str = str.Replace("drop", "");
str = str.Replace("exec", "");
str = str.Replace("execute", "");
str = str.Replace("db_name()", "");
str = str.Replace("table", "");
if (str.Trim().ToString() == "")
str = "";
return str;
}
方法4:
public static string FilterNullToEmpty(string str)
{
if (string.IsNullOrEmpty(str))
{
return "";
}
else
{
return str;
}
}
方法5:
public static string GetCheckBoxListValue(CheckBoxList cbl, TextBox tb)
{
string strRtn = "";
string str = "";
for (int i = 0; i < cbl.Items.Count; i++)
{
if (cbl.Items[i].Selected)
{
str += cbl.Items[i].Value + ",";
}
}
if (!string.IsNullOrEmpty(str))
{
int len = str.Length;
str = str.Substring(0, len - 1);
}
string str_others = tb.Text.Trim();
if (!string.IsNullOrEmpty(str_others))
{
str += ("|" + str_others);
}
strRtn += str;
return strRtn;
}
.TextBoxLine
{
padding: 5px 0px 0px 3px;
border-width: 0px 0px 1px 0px;
border-color: #EEEEEE;
border-style: outset;
background-color: #FFFFFF;
}