locked
Passing selected row from gridview to dropdown RRS feed

  • Question

  • Kindly help me passing selected row in gridview to my dropdown. I have 1 gridview, 1 textbox and 1 dropdown list box. My dropdown is populated by SqlDataSource from my table Country. On my gridview, I have 3 columns, which are SELECT, NAME and COUNTRY. Under SELECT column, I have my hyperlinked Select, every time I clicked on a certain row NAME will pass in textbox (no problem with that), but in my dropdown it does not populates the COUNTRY that I choose. For example, I have Jack for name and USA for country. Beside Jack and USA, I have a hyperlink Select, when I click Select, Jack will display on my textbox and supposed to be USA will display on my dropdown but not displaying instead it says an error "'cboCountry' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value".

    I have tried the codes below:

    protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
    {
       txtname.Text = GridView2.SelectedRow.Cells[1].Text;
       cboCountry.Text = GridView2.SelectedRow.Cells[2].Text;
    }

    Only the textbox os working, no luck at all in dropdown...I'm using c# and asp.net. Any help would be appreciated. Thanks in advance. God Bless

    • Moved by Tom Phillips Friday, May 17, 2013 4:07 PM .Net question
    • Moved by Mike Feng Monday, May 20, 2013 2:59 PM
    Friday, May 17, 2013 12:24 PM

Answers

All replies

  • This is a .NET question that you can post it in .NET forum where you will get better answer.

    It lloks like the way you set the value for the dropdown is wrong. You may need to set the selectedValue of your dropdown to the Gridview text.


    Please use Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful.

    • Proposed as answer by Mike Feng Monday, May 20, 2013 2:58 PM
    Friday, May 17, 2013 12:35 PM
  • Hi Petra,

    Please try asp.net issue on asp.net forum: http://forums.asp.net/ 

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Just Karl Friday, October 4, 2013 2:01 AM
    Monday, May 20, 2013 2:59 PM