I am trying to pass a 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 code 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 is working, no luck at all in dropdown. I'm using C# and asp.net.
Try to use cboCountry.SelectedItem.Text
.After getting the value set this thing to dropdown
like
protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
{
txtname.Text = GridView2.SelectedRow.Cells[1].Text;
cboCountry.SelectedItem.Text = GridView2.SelectedRow.Cells[2].Text;
}
Hope it works
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.