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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Trying to prevent the first dropdownlist value changing my database field unless I need to in C#

Trying to prevent the first dropdownlist value changing my database field unless I need to in C#

Scheduled Pinned Locked Moved ASP.NET
csharpdatabasehelp
5 Posts 2 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.
  • N Offline
    N Offline
    Norris Chappell
    wrote on last edited by
    #1

    Hi, I was able to solve my issue.

    string value = DataBinder.Eval(e.Row.DataItem, "SAPLeader").ToString();
    dd.SelectedValue = value;
    dd.SelectedIndex = dd.Items.IndexOf(dd.Items.FindByText(value.ToString()));

    This is the fixed. :)

    H 1 Reply Last reply
    0
    • N Norris Chappell

      Hi, I was able to solve my issue.

      string value = DataBinder.Eval(e.Row.DataItem, "SAPLeader").ToString();
      dd.SelectedValue = value;
      dd.SelectedIndex = dd.Items.IndexOf(dd.Items.FindByText(value.ToString()));

      This is the fixed. :)

      H Offline
      H Offline
      Herman T Instance
      wrote on last edited by
      #2

      dd.Text? Shouldn't you use dd.SelectedValue or dd.SelectedItem?

      In Word you can only store 2 bytes. That is why I use Writer.

      N 1 Reply Last reply
      0
      • H Herman T Instance

        dd.Text? Shouldn't you use dd.SelectedValue or dd.SelectedItem?

        In Word you can only store 2 bytes. That is why I use Writer.

        N Offline
        N Offline
        Norris Chappell
        wrote on last edited by
        #3

        I changed it to dd.SelectedValue = value; It still doesn't work. The issue is that once I select EDIT the current value in the SAPLeader field goes away and the dropdownlist is now showing the first value and that is the one it choses when you select UPDATE. What I would like it do is to select the right dropdown value when the dropdownlist loads.

        H 1 Reply Last reply
        0
        • N Norris Chappell

          I changed it to dd.SelectedValue = value; It still doesn't work. The issue is that once I select EDIT the current value in the SAPLeader field goes away and the dropdownlist is now showing the first value and that is the one it choses when you select UPDATE. What I would like it do is to select the right dropdown value when the dropdownlist loads.

          H Offline
          H Offline
          Herman T Instance
          wrote on last edited by
          #4

          try something LIKE:

          ddlData.SelectedIndex=ddlData.Items.IndexOf(ddlData.Items.FindByText("value"));

          In Word you can only store 2 bytes. That is why I use Writer.

          N 1 Reply Last reply
          0
          • H Herman T Instance

            try something LIKE:

            ddlData.SelectedIndex=ddlData.Items.IndexOf(ddlData.Items.FindByText("value"));

            In Word you can only store 2 bytes. That is why I use Writer.

            N Offline
            N Offline
            Norris Chappell
            wrote on last edited by
            #5

            I inserted that line into my code but I still don't see the correct dropdownlist value but only the first value. Do I need to do something with that line of code elsewhere in my code? dd.DataBind(); string value = DataBinder.Eval(e.Row.DataItem, "SAPLeader").ToString(); dd.SelectedIndex = dd.Items.IndexOf(dd.Items.FindByText("value")); I inserted some breakpoints and I can see the correct value however, then I do an UPDATE it takes the first value in my dropdownlist and replaces the current value. Thanks,

            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