A WebControl with a checkbox

Source: Internet
Author: User
Tags bool
Web Thank you, no in return, put something.

Just saw a lot of people below ask a DataTable or table to add a selection box, in fact, if you can do a webcontrol to achieve this function, the bottom is I do a webcontrol with a checkbox, because the annotation is more complete, So I'm not going to explain it.

Using System;
Using System.Collections;
Using System.Web.UI.WebControls;
Using System.Web.UI;



Namespace Bigeagle.Web.WebControls
{
<summary>
<br> custom controls, table</br> with selection boxes
<br>Author:Bigeagle@163.net</br>
<br>Date:2001/10/10</br>
&LT;BR&GT;HISTORY:2001/10/10 finished</br>
</summary>
<remarks>
Inherit System.Web.UI.WebControls.Table, add CheckedValue property,
An array that returns the values of the selected Checktablerow for the occasion of multiple selections
</remarks>
public class CheckTable:System.Web.UI.WebControls.Table
{

<summary>
Whether to use a checkbox
</summary>
<remarks> If False, checkbox</remarks> is not displayed
private bool M_busecheck;


<summary>
ֵ Select array
</summary>
<remarks> returns the value of the selected Checktablerow </remarks>
Private ArrayList M_arrcheckedvalue;

<summary>
Gets the properties of the Select array
</summary>
<remarks> read-only properties </remarks>
Public ArrayList CheckedValue
{
Get
{
return this.m_arrcheckedvalue;
}
}

<summary>
Access to use CheckBox properties
</summary>
public bool Usecheck
{
Get
{
return this.m_busecheck;
}
Set
{
This.m_busecheck = value;
}
}


<summary>
Constructors
</summary>
Public CheckTable ()
{
This.m_arrcheckedvalue = new ArrayList ();
This.m_busecheck = true;
}

<summary>
Overloaded Parent class method
</summary>
<param name= "E" ></param>
protected override void OnLoad (System.EventArgs e)
{
if (This.m_busecheck)
{
Try
{
for (int i = 0; I < this. Rows.Count; i++)
{
Checktablerow ctr = (checktablerow) this. Rows[i];
CheckBox cb = (checkbox) Ctr. FindControl (Ctr. Value);
if (CB). Checked)
{
This.m_arrCheckedValue.Add (Ctr. Value);
}
}

}
catch (Exception)//General exception is due to duplicate control ID
{
Throw (New Exception ("Duplicate control ID appears");
}
}
}//end method


}//end class
}//end method

Using System;
Using System.Web.UI.WebControls;
Using System.Web.UI;

Namespace Bigeagle.Web.WebControls
{
<summary>
<br> custom controls, tablerow</br> with selection boxes
<br>Author:Bigeagle@163.net</br>
<br>Date:2001/10/10</br>
&LT;BR&GT;HISTORY:2001/10/10 finished</br>
</summary>
<remarks>
Inherits System.Web.UI.WebControls.TableRow as the TableRow of the custom control checktable,
Add a value attribute and a checkbox compared to TableRow
</remarks>
public class CheckTableRow:System.Web.UI.WebControls.TableRow
{
<summary>
Value
</summary>
private string M_strvalue;

<summary>
Whether to use a checkbox
</summary>
<remarks> If False, checkbox</remarks> is not displayed
private bool M_busecheck;

<summary>
accessing properties of Value
</summary>
public string Value
{
Get
{
return this.m_strvalue;
}
Set
{
This.m_strvalue = value;
}
}

<summary>
Access to use CheckBox properties
</summary>
public bool Usecheck
{
Get
{
return this.m_busecheck;
}
Set
{
This.m_busecheck = value;
}
}


<summary>
Constructors
</summary>
Public Checktablerow ()
{
This.m_strvalue = "";
This.m_busecheck = true;


}

<summary>
Overloaded Parent class method
</summary>
<returns> Control Combination </returns>
<remarks> add a td</remarks> with a checkbox
protected override System.Web.UI.ControlCollection Createcontrolcollection ()
{
ControlCollection cc = base. Createcontrolcollection ();
if (This.m_busecheck)
{
TableCell td = New TableCell ();
Td. BackColor = this. BackColor;
Td. VerticalAlign = Verticalalign.top;
CheckBox cb = new checkbox ();
Cb.id = This.m_strvalue;
Td. Controls.Add (CB);
Cc. ADD (TD);
}
return cc;
}//end method


}//end class
}//end namespace


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.