Checkbox in DataList
-
Hi friends, I am using DataList control which have checkbox control.when i click checkall button All checkbox are selected.this is my code for (int i = 0; i < Dgr_hotel.Items.Count - 1; i++) { ((CheckBox)Dgr_hotel.FindControl("chk_Box")).Checked = true; } but I am getting Error this Error Object reference not set to an instance of an object. How can I do ? pl help me
Thank& Regards Vijay s
-
Hi friends, I am using DataList control which have checkbox control.when i click checkall button All checkbox are selected.this is my code for (int i = 0; i < Dgr_hotel.Items.Count - 1; i++) { ((CheckBox)Dgr_hotel.FindControl("chk_Box")).Checked = true; } but I am getting Error this Error Object reference not set to an instance of an object. How can I do ? pl help me
Thank& Regards Vijay s
-
Hi friends, I am using DataList control which have checkbox control.when i click checkall button All checkbox are selected.this is my code for (int i = 0; i < Dgr_hotel.Items.Count - 1; i++) { ((CheckBox)Dgr_hotel.FindControl("chk_Box")).Checked = true; } but I am getting Error this Error Object reference not set to an instance of an object. How can I do ? pl help me
Thank& Regards Vijay s
Vijayitsb wrote:
for (int i = 0; i < Dgr_hotel.Items.Count - 1; i++) { ((CheckBox)Dgr_hotel.FindControl("chk_Box")).Checked = true; }
Vijayitsb wrote:
when i click checkall button All checkbox are selected.
How cum? In the above given code you are not navigating through the items of the DataList Control to find the CheckBox and mark it Checked. Most importantly the
i
value is not used anywhere in the loop. It will not serve your purpose in any way. You can try the below code to do the sameforeach (DataListItem Items in DataList1.Items) { ((CheckBox)Items.FindControl("chkBox")).Checked = true; }
- Regards -
JON
Life is not measured by the amount of breaths we take, but by the moments that take our breath away.