1

Code:

DataSet ds = _dalEquipmentwiseCheckList.getEquipmentName();

ddEquipmentName.DataSource = ds.Tables[0].DefaultView;

ddEquipmentName.DataTextField = ds.Tables[0].Columns[1].ToString();
ddEquipmentName.DataValueField = ds.Tables[0].Columns[0].ToString();
ddEquipmentName.DataBind();

What I want is: when selecting a row in the GridView, the corresponding equipment name should get selected in the dropdown list:

var selectRow = MyGridView.SelectedRow;

ddEquipmentName.SelectedValue = selectRow.Cells[2].Text;
****//this is giving me error****
dhiraj
  • 73
  • 2
  • 14
  • This will help you--easily translated to C#: http://stackoverflow.com/questions/17981920/how-to-select-a-value-of-a-dropdownlist-that-has-been-returned-from-a-database – Garrison Neely Aug 13 '13 at 20:22

3 Answers3

1

Selected value does not work in this way. Try this:

ddEquipmentName.SelectedIndex = ddEquipmentName.Items.IndexOf(ddEquipmentName.Items.FindByText(selectRow.Cells[2].Text));
afzalulh
  • 7,925
  • 2
  • 26
  • 37
0

You can try :

GridViewRow selectRow = MyGridView.SelectedRow;    
ddEquipmentName.selectedItem.Text = selectRow.Cells[2].Text;
Irshad
  • 3,071
  • 5
  • 30
  • 51
0
 void setDataContext()
{
    var selectRow = GridEquipmentChechList.MyGridView.SelectedRow;
    if (selectRow != null)
    {
        txtECNumber.Text = selectRow.Cells[1].Text;
        **ddEquipmentName.SelectedIndex = ddEquipmentName.Items.IndexOf(ddEquipmentName.Items.FindByText(selectRow.Cells[2].Text));**
        **ddDescription.SelectedIndex = ddDescription.Items.IndexOf(ddDescription.Items.FindByText(selectRow.Cells[3].Text));**
    }
}
Irshad
  • 3,071
  • 5
  • 30
  • 51
dhiraj
  • 73
  • 2
  • 14