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. Problem with checkbox binding in DetailsView

Problem with checkbox binding in DetailsView

Scheduled Pinned Locked Moved ASP.NET
questionwpfwcfxmlhelp
8 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.
  • L Offline
    L Offline
    lvq684
    wrote on last edited by
    #1

    Hi. I have a detailsview with a checkbox. This checkbox´s state should be determined from a ObjectDataSource which "fills" the detailsview. And, if the checkbox´s state is changed by the user, the ObjectDataSource´s UpdateMethod should of course save this new state. Problem is, that i dont know how to bind this checfield, since the 'Checked' attribute only takes true/false, and my data is in xml. Therefore i only have "true"/"false" data as strings. So how do i bind this checkbox state? And save the new state when the user changes it? Thanks alot!

    P 1 Reply Last reply
    0
    • L lvq684

      Hi. I have a detailsview with a checkbox. This checkbox´s state should be determined from a ObjectDataSource which "fills" the detailsview. And, if the checkbox´s state is changed by the user, the ObjectDataSource´s UpdateMethod should of course save this new state. Problem is, that i dont know how to bind this checfield, since the 'Checked' attribute only takes true/false, and my data is in xml. Therefore i only have "true"/"false" data as strings. So how do i bind this checkbox state? And save the new state when the user changes it? Thanks alot!

      P Offline
      P Offline
      Paramhans Dubey
      wrote on last edited by
      #2

      what is the data type of your field you want to bind?

      L 1 Reply Last reply
      0
      • P Paramhans Dubey

        what is the data type of your field you want to bind?

        L Offline
        L Offline
        lvq684
        wrote on last edited by
        #3

        The data type is string. The field contains "false" or "true". And should be bound to the checkbox´ checked attribute which takes boolean. Thanks!

        P 1 Reply Last reply
        0
        • L lvq684

          The data type is string. The field contains "false" or "true". And should be bound to the checkbox´ checked attribute which takes boolean. Thanks!

          P Offline
          P Offline
          Paramhans Dubey
          wrote on last edited by
          #4

          Try This

          Checked='<%#(Eval("Field").ToString() == "true" ? true : false) %>'

          L 1 Reply Last reply
          0
          • P Paramhans Dubey

            Try This

            Checked='<%#(Eval("Field").ToString() == "true" ? true : false) %>'

            L Offline
            L Offline
            lvq684
            wrote on last edited by
            #5

            Thanks alot! But it did not solve my problem. With this solution, i can DISPLAY the correct data (if the box are checked or not). But when the user updates the data (changes the checked state), the ObjectDataSource´s UpdateMethod sees the field as null. Is there a workaround on this? :)

            P 1 Reply Last reply
            0
            • L lvq684

              Thanks alot! But it did not solve my problem. With this solution, i can DISPLAY the correct data (if the box are checked or not). But when the user updates the data (changes the checked state), the ObjectDataSource´s UpdateMethod sees the field as null. Is there a workaround on this? :)

              P Offline
              P Offline
              Paramhans Dubey
              wrote on last edited by
              #6

              <UpdateParameters>
              <asp:ControlParameter ControlID="CheckBox1" Name="Field"
              PropertyName="Checked" Type="String" />
              </UpdateParameters>

              L 1 Reply Last reply
              0
              • P Paramhans Dubey

                <UpdateParameters>
                <asp:ControlParameter ControlID="CheckBox1" Name="Field"
                PropertyName="Checked" Type="String" />
                </UpdateParameters>

                L Offline
                L Offline
                lvq684
                wrote on last edited by
                #7

                Thanks. But I cant get it to work. Can you please post the full example including the DetailsView and CheckBox tags? Thanks alot! :)

                M 1 Reply Last reply
                0
                • L lvq684

                  Thanks. But I cant get it to work. Can you please post the full example including the DetailsView and CheckBox tags? Thanks alot! :)

                  M Offline
                  M Offline
                  michelle sollicito
                  wrote on last edited by
                  #8

                  try something like this? make sure in the prerender event you have soemthing like this.. CheckBox chkdnslive = (CheckBox)detailsView.FindControl("chkDNSLive"); chkdnslive.Checked = true; //default to true

                  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