Using the following code you can easily bind a GridView with a XML file and provide check box select all functionality.
We will cover this article in the following sections:
1. Getting data from XML file and Binding Gridview with data.
2. Design GridView with SelectAll CheckBox in HeaderRow.
Now let's get started with step 1.
1. Getting data from XML file and Binding Gridview with data
I have used a Default.aspx page to show a grid on that page. When the page is load, following code get data from XML file and bind the grid. Additionally it also store number of rows in viewstate for select all function.
protected void Page_Load(object sender, EventArgs e)
DataSet dsCatalog = new DataSet();
gvCdCatalog.DataSource = dsCatalog.Tables;
ViewState["RowCount"] = dsCatalog.Tables.Rows.Count;
2. Design GridView with SelectAll CheckBox in HeaderRow
In the above function, I used 'gvCdCatalog_ctl01_chkSelectAll’ it is genrated at runtime by the browser. You can see it by right click on webpage and select view source.
So in your case, you have to change the id according to your gridview id and chekbox id like here ‘gvCdCatalog’ is GridViewId and ‘chkSelectAll’ is checkbox id. Then we check that this check box is checked or not. If it is checked then start a for loop and it get each check box and assign true to it’s checked property.