C# 复选框列表中只选中一个复选框
我在asp.net c#应用程序中编写了一个函数C# 复选框列表中只选中一个复选框,c#,asp.net,C#,Asp.net,我在asp.net c#应用程序中编写了一个函数 public void FillAfterClose(string Names) { string[] arrGroup = Names.ToString().Split(','); foreach (object obj in arrGroup) { for (int i = 0; i < chklLicence
public void FillAfterClose(string Names)
{
string[] arrGroup = Names.ToString().Split(',');
foreach (object obj in arrGroup)
{
for (int i = 0; i < chklLicenceTypes.Items.Count; i++)
{
if (chklLicenceTypes.Items[i].Text == obj.ToString())
{
chklLicenceTypes.Items[i].Selected = true;
}
}
}
}
public void FillAfterClose(字符串名称)
{
字符串[]arrGroup=Names.ToString().Split(',');
foreach(ARR组中的对象obj)
{
对于(int i=0;i
在aspx文件中,我通过代码绑定了一个带有名称和值对的复选框
<asp:CheckBoxList ID="chklLicenceTypes" RepeatDirection="Horizontal" AutoPostBack="false"
CausesValidation="false" RepeatColumns="3" RepeatLayout="Table" runat="server">
</asp:CheckBoxList>
在浏览器中呈现页面后,复选框列表将填充
- 财产和伤亡[]
- 事故与健康[]
- 生活[]
- 随意性[]
- 无[]
我希望选中“财产和伤亡、事故和健康、生命”复选框。如果字符串正好是:
var names="Property and Casualty, Accident and Health, Life";
然后,我会发现拆分末尾的空格有问题。我想改变这一行:
string[] arrGroup = Names.ToString().Split(',');
string[] arrGroup = names.Split(',').Select (s =>s.Trim()).ToArray();
这将导致:
new []
{
"Property and Casualty",
" Accident and Health",
" Life"
};
new []
{
"Property and Casualty",
"Accident and Health",
"Life"
};
关于这一行:
string[] arrGroup = Names.ToString().Split(',');
string[] arrGroup = names.Split(',').Select (s =>s.Trim()).ToArray();
这将导致:
new []
{
"Property and Casualty",
" Accident and Health",
" Life"
};
new []
{
"Property and Casualty",
"Accident and Health",
"Life"
};