Add a CheckBox control column to the DataGrid control

Source: Internet
Author: User

To add a CheckBox control column for the DataGrid space, you first need to add a template column to the DataGrid control and then add a CheckBox control to the template column

There is a DataGridItem class in the System.Web.UI.WebControls namespace that represents the items in the DataGrid control. There is a FindControl method in the class that searches the current naming container for a server control with the specified ID parameter, using the following method:

Public virtual control FindControl (string id);
Parameters: ID to find the identity value of the control
Return value: Returns the control if the specified control exists, or returns an empty if it does not exist

Click event for the Get Selected item button (Example of adding a CheckBox control column in the DataGrid control)
private void Renamefolder_click (object sender, System.Web.UI.ImageClickEventArgs e)
{
System.Web.UI.WebControls.CheckBox CheckBox1;
String ID;
System.Text.StringBuilder strmsg=new System.Text.StringBuilder ("fname field values for selected items are: foreach (DataGridItem odatagriditem in Datagrid1.items)
{
checkbox1= (checkbox) Odatagriditem.findcontrol ("CheckBox1");
if (CheckBox1. Checked)
{
Id= ((HyperLink) (Odatagriditem.findcontrol ("HyperLink1")). Text;
strmsg. Append (id+ "<br>}
Message.text=strmsg. ToString ();
}
}

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.