Multi Select Checkbox using ListView

Posted by Parsa on Stack Overflow See other posts from Stack Overflow or by Parsa
Published on 2012-10-06T15:34:49Z Indexed on 2012/10/06 15:36 UTC
Read the original article Hit count: 411

Filed under:
|

I have a CheckBox in the header of ListView. I write a code to select all Checkboxes in ItemTemplate automatically when the user select the checkBox in the header of ListView.

This code is useful, when you bind your ListView in DataPager_PreRender.

protected void DataPager1_PreRender(object sender, EventArgs e)

{
    //get the user id of the current user
    Guid userGuid = (Guid)Membership.GetUser().ProviderUserKey;

    ListView1.DataSource = MyClass.MyStaticMethod(userGuid.ToString());
    ListView1.DataBind();
}

protected void ListView1_ItemCreated(object sender, ListViewItemEventArgs e) {

    //Find the checkBox in each Row
    CheckBox checkBoxRow = e.Item.FindControl("CheckBoxRow") as CheckBox;

    //Assign the value of checkBoxHeader to the checkBoxRow
    checkBoxRow.Checked = CheckBoxHeader.Checked;
}

protected void ListView1_PagePropertiesChanged(object sender, EventArgs e) { // assign false value to the CheckBoxHeader when user click on the DataPager // so if checkboxheader is true in the page 1, when user select Page 2,this check box will be false // therefore all checkbox rows will be false in the new page.

       if (CheckBoxHeader.Checked == true)
        CheckBoxHeader.Checked = false;
}

© Stack Overflow or respective owner

Related posts about listview

Related posts about checkbox