<asp:CheckBox ID="CheckBox1" runat="server" />
<asp:CheckBox ID="CheckBox2" runat="server" />
<asp:CheckBox ID="CheckBox3" runat="server" />
<asp:CheckBox ID="CheckBox4" runat="server" />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
In code behind:
public enum BitFlag : byte
{
First = 1,
Second = 2,
Third = 4,
Fourth = 8
}
public void CheckFlag(BitFlag bFlag)
{
if ((bFlag & BitFlag.First) == BitFlag.First)
CheckBox1.Checked = true;
if ((bFlag & BitFlag.Second) == BitFlag.Second)
CheckBox2.Checked = true;
if ((bFlag & BitFlag.Third) == BitFlag.Third)
CheckBox3.Checked = true;
if ((bFlag & BitFlag.Fourth) == BitFlag.Fourth)
CheckBox4.Checked = true;
}
protected void Button1_Click(object sender, EventArgs e)
{
BitFlag bFlag = new BitFlag();//= BitFlag.First;
if (CheckBox1.Checked)
bFlag |= BitFlag.First;
if (CheckBox2.Checked)
bFlag |= BitFlag.Second;
if (CheckBox3.Checked)
bFlag |= BitFlag.Third;
if (CheckBox4.Checked)
bFlag |= BitFlag.Fourth;
CheckFlag(bFlag);
}
Thanks
Mahesh
<asp:CheckBox ID="CheckBox2" runat="server" />
<asp:CheckBox ID="CheckBox3" runat="server" />
<asp:CheckBox ID="CheckBox4" runat="server" />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
In code behind:
public enum BitFlag : byte
{
First = 1,
Second = 2,
Third = 4,
Fourth = 8
}
public void CheckFlag(BitFlag bFlag)
{
if ((bFlag & BitFlag.First) == BitFlag.First)
CheckBox1.Checked = true;
if ((bFlag & BitFlag.Second) == BitFlag.Second)
CheckBox2.Checked = true;
if ((bFlag & BitFlag.Third) == BitFlag.Third)
CheckBox3.Checked = true;
if ((bFlag & BitFlag.Fourth) == BitFlag.Fourth)
CheckBox4.Checked = true;
}
protected void Button1_Click(object sender, EventArgs e)
{
BitFlag bFlag = new BitFlag();//= BitFlag.First;
if (CheckBox1.Checked)
bFlag |= BitFlag.First;
if (CheckBox2.Checked)
bFlag |= BitFlag.Second;
if (CheckBox3.Checked)
bFlag |= BitFlag.Third;
if (CheckBox4.Checked)
bFlag |= BitFlag.Fourth;
CheckFlag(bFlag);
}
Thanks
Mahesh
No comments:
Post a Comment