Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Checkbox in DataList

Checkbox in DataList

Scheduled Pinned Locked Moved ASP.NET
helpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vijayitsb
    wrote on last edited by
    #1

    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

    P J 2 Replies Last reply
    0
    • V Vijayitsb

      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

      P Offline
      P Offline
      Prateek G
      wrote on last edited by
      #2

      Try this foreach(CheckBox c in Page.Form.Controls) { c.Checked = true; }

      1 Reply Last reply
      0
      • V Vijayitsb

        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

        J Offline
        J Offline
        John ph
        wrote on last edited by
        #3

        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 same

        foreach (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.


        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups