复选框的问题
我现在是想把复选框里的内容添加到数据库中去,我如何获取复选框里的内容,就是说想其他的字段都可以写成 string name=textBox.text.trim().tostring() 想复选框如何选呢?--------------------编程问答-------------------- bool bln=CheckBox1.Checked
string str=CheckBox1.Value.ToString() --------------------编程问答-------------------- 將多個復選框當作成一個整體(如為radion.button的話),如點的是哪個將此值寫入﹔
如為CHECKBOX的話:用參數:
param1.value=checkedbox.checked ;
不明白的話,請留言。 --------------------编程问答-------------------- 页面上拖一个CheckBoxList
<asp:CheckBoxList ID ="chklist1" runat ="server">
<asp:ListItem Text ="a" Value ="a" Selected ="True"></asp:ListItem>
<asp:ListItem Text ="b" Value ="b"></asp:ListItem>
<asp:ListItem Text ="c" Value ="c" Selected ="True"></asp:ListItem>
<asp:ListItem Text ="d" Value ="d"></asp:ListItem>
</asp:CheckBoxList>
CS端:
string temp = string.Empty;
for (int i = 0; i < chklist1.Items.Count; i++)
{
if (chklist1.Items[i].Selected)
{
temp += chklist1.Items[i].Value;
}
}
Response.Write(temp); --------------------编程问答-------------------- string check=this.checkbox.checked.tostring();? --------------------编程问答-------------------- if (this.checkedListBox1.CheckedItems.Count > 0)
{
foreach (string item in this.checkedListBox1.CheckedItems)
{
this.textbox.text=item;
} --------------------编程问答-------------------- checkBox1.Text --------------------编程问答-------------------- 顶3楼写得很详细了,用他的按需要改一下就行了,就是循环判断CheckBoxList中的每一项是否被选中,然后将被选中的text或value属性读出来 --------------------编程问答-------------------- 看MSDN --------------------编程问答-------------------- 页面上拖一个CheckBoxList
<asp:CheckBoxList ID ="chklist1" runat ="server">
<asp:ListItem Text ="a" Value ="a" Selected ="True"> </asp:ListItem>
<asp:ListItem Text ="b" Value ="b"> </asp:ListItem>
<asp:ListItem Text ="c" Value ="c" Selected ="True"> </asp:ListItem>
<asp:ListItem Text ="d" Value ="d"> </asp:ListItem>
</asp:CheckBoxList>
CS端:
string temp = string.Empty;
for (int i = 0; i < chklist1.Items.Count; i++)
{
if (chklist1.Items[i].Selected)
{
temp += chklist1.Items[i].Value;
}
}
Response.Write(temp); --------------------编程问答-------------------- --------------------编程问答-------------------- private void chkLSelect_SelectedIndexChanged(object sender, EventArgs e)
{
if (chkLSelect.GetItemChecked(0))//判断第0项是否选中
{
chkLSelect.SetItemChecked(0, true);//设置第0项是否选中
}
this.Txt_FieldValue.Text = null;
for (int j = 0; j < chkLSelect.Items.Count; j++)
{
if (chkLSelect.GetItemChecked(j))
{
this.Txt_FieldValue.Text = this.Txt_FieldValue.Text + chkLSelect.Items[j].ToString() + " ";
}
}
}
补充:.NET技术 , C#