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. Dropdown in Gridview

Dropdown in Gridview

Scheduled Pinned Locked Moved ASP.NET
help
7 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.
  • B Offline
    B Offline
    Ballita
    wrote on last edited by
    #1

    Hi, I have a gridview which contain dropdownlist in every row. And there is a Save button in that page. I want to save the dropdownlist's value on clicking on the save button. But I am getting an error "Object reference not set to an instance of an object". Please look at the code I am using: foreach (GridViewRow rec in this.gvsqldesc.Controls[0].Controls) { DropDownList ddlval = new DropDownList(); ddlval = (DropDownList)rec.FindControl("ddlvalidation"); string str = ddlval.SelectedItem.Text; }

    Thanks & Regards Mishra

    I J 2 Replies Last reply
    0
    • B Ballita

      Hi, I have a gridview which contain dropdownlist in every row. And there is a Save button in that page. I want to save the dropdownlist's value on clicking on the save button. But I am getting an error "Object reference not set to an instance of an object". Please look at the code I am using: foreach (GridViewRow rec in this.gvsqldesc.Controls[0].Controls) { DropDownList ddlval = new DropDownList(); ddlval = (DropDownList)rec.FindControl("ddlvalidation"); string str = ddlval.SelectedItem.Text; }

      Thanks & Regards Mishra

      I Offline
      I Offline
      Imran Khan Pathan
      wrote on last edited by
      #2

      Ballita wrote:

      ddlval = (DropDownList)rec.FindControl("ddlvalidation");

      have you checked that above line find the dropwdownlist or return Null value? best regard pAthAn

      please don't forget to vote on the post that helped you.

      B 1 Reply Last reply
      0
      • I Imran Khan Pathan

        Ballita wrote:

        ddlval = (DropDownList)rec.FindControl("ddlvalidation");

        have you checked that above line find the dropwdownlist or return Null value? best regard pAthAn

        please don't forget to vote on the post that helped you.

        B Offline
        B Offline
        Ballita
        wrote on last edited by
        #3

        It is returning null value.

        Thanks & Regards Mishra

        I 1 Reply Last reply
        0
        • B Ballita

          It is returning null value.

          Thanks & Regards Mishra

          I Offline
          I Offline
          Imran Khan Pathan
          wrote on last edited by
          #4

          Ballita wrote:

          foreach (GridViewRow rec in this.gvsqldesc.Controls[0].Controls)

          try this and check out again foreach(GridViewRow rec in this.gvsqldesc.Rows) BesT regaRD pathan

          please don't forget to vote on the post that helped you.

          B 1 Reply Last reply
          0
          • I Imran Khan Pathan

            Ballita wrote:

            foreach (GridViewRow rec in this.gvsqldesc.Controls[0].Controls)

            try this and check out again foreach(GridViewRow rec in this.gvsqldesc.Rows) BesT regaRD pathan

            please don't forget to vote on the post that helped you.

            B Offline
            B Offline
            Ballita
            wrote on last edited by
            #5

            Hey, I have tried this one also. It is not returning null but it is not fetching the values.

            Thanks & Regards Mishra

            I 1 Reply Last reply
            0
            • B Ballita

              Hey, I have tried this one also. It is not returning null but it is not fetching the values.

              Thanks & Regards Mishra

              I Offline
              I Offline
              Imran Khan Pathan
              wrote on last edited by
              #6

              Ballita wrote:

              ddlval.SelectedItem.Text;

              ddlval.SelectedValue;

              bEst Regard pAthaN

              please don't forget to vote on the post that helped you.

              1 Reply Last reply
              0
              • B Ballita

                Hi, I have a gridview which contain dropdownlist in every row. And there is a Save button in that page. I want to save the dropdownlist's value on clicking on the save button. But I am getting an error "Object reference not set to an instance of an object". Please look at the code I am using: foreach (GridViewRow rec in this.gvsqldesc.Controls[0].Controls) { DropDownList ddlval = new DropDownList(); ddlval = (DropDownList)rec.FindControl("ddlvalidation"); string str = ddlval.SelectedItem.Text; }

                Thanks & Regards Mishra

                J Offline
                J Offline
                John Gathogo
                wrote on last edited by
                #7

                Try something like this: foreach (GridViewRow rec in this.gvsqldesc.Rows) { string str = (DropDownList)rec.FindControl("ddlvalidation").SelectedItem.Text; } Here am assuming that the name of you gridview is 'gvsqldesc'. All the Best.

                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