2013-05-17 44 views
0

我試圖將選定的行在gridview中傳遞到我的下拉列表中。我有1個gridview,1個文本框和1個下拉列表框。我的下拉列表由我的表Country中的SqlDataSource填充。在gridview中將選定的行傳遞給下拉列表框

在我的gridview上,我有3列,它們是SELECT,NAME和COUNTRY。在SELECT列下,我有我的超鏈接選擇,每次我點擊某一行時,NAME都會在文本框中傳遞(沒有問題),但是在我的下拉列表中沒有填充我選擇的COUNTRY。

例如,我有名字傑克和國家美國。除了傑克和美國,我有一個超鏈接選擇,當我點擊選擇,傑克將顯示在我的文本框,應該是美國將顯示在我的下拉但不顯示,而不是它說一個錯誤:

'cboCountry' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value

我有嘗試下面的代碼:

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

只有文本框工作,沒有運氣在下拉。我正在使用C#和asp.net。

回答

0

嘗試使用cboCountry.SelectedItem.Text。經過越來越設定這東西的價值,以dropdown

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

希望工程

+0

非常感謝你拉胡爾。有用。再次感謝! – user2388316

+0

歡迎您... – Rahul

相關問題