WebForm gets the value selected by checkbox Several simple examples of of
- 2020-12-18 01:48:11
- OfStack
PS: Recently, I was working on the module of authority management. I found many places to use checkbox, so I wrote a simple example for future study and use.
1. Front-end page:
<form id="form1" method="get" runat="server">
<input name="chk_per" type="checkbox" value="3" /> zhang 3
<input name="chk_per" type="checkbox" value="4" /> li 4
<input name="chk_per" type="checkbox" value="5" /> The king 5
<input name="chk_per" type="checkbox" value="6" /> zhao 6
<input name="chk_per" type="checkbox" value="7" /> sun
<input name="chk_per" type="checkbox" value="8" /> The pig 8
<input type="submit" id="btnOK" value=" submit " />
</form>
2. Background method:
#region Gets returned from the front page CheckBox The value of the void GetCheckBoxValue()
/// <summary>
/// Gets returned from the front page CheckBox The value of the
/// <para>Request.Form["chk_per"] Separated by a comma, gets all the selected ones CheckBox The value of the </para>
/// </summary>
private void GetCheckBoxValue()
{
string user = Request["chk_per"];
string[] users = user.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
string s = string.Empty;
foreach (var item in users)
{
s += item + " | ";
}
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
// Test call
GetCheckBoxValue();
}
}