CheckBox And CheckBoxList


 CheckBox

Source
<asp:CheckBox ID="chkBox" runat="server" Text="Check Now..!" />
<asp:Button ID="btnCheckBox" runat="server" Text="Test" OnClick="btnCheckBox_Click" />
<asp:TextBox ID="txtCheck" runat="server" Style="font-weight: 700"></asp:TextBox>

C#
 


protected void btnCheckBox_Click(object sender, EventArgs e)
        {
            if (chkBox.Checked)
            {
                txtCheck.Text = "Checked";
            }
            else
            {
                txtCheck.Text = "Not Checked";
            }

        }


  CheckBox List

Source

<asp:CheckBoxList ID="chkLst" runat="server" Style="font-weight: 700">
<asp:ListItem Value="1">A</asp:ListItem>
<asp:ListItem Value="2">B</asp:ListItem>
</asp:CheckBoxList>
<asp:Button ID="btnChkLst" runat="server" Text="Check" OnClick="btnChkLst_Click" Style="font-weight: 700" />
<asp:TextBox ID="txtChkLst" runat="server" Style="font-weight: 700"></asp:TextBox>
                   
 

C#
protected void btnChkLst_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < chkLst.Items.Count; i++)
            {
                if (chkLst.Items[i].Selected)
                {
                    txtChkLst.Text += chkLst.Items[i].Text;
                }
            }
        }

No comments:

Post a Comment