代码:
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();
我想要的是:在GridView中选择一行时,相应的设备名称 应该在下拉列表中选择:
var selectRow = MyGridView.SelectedRow;
ddEquipmentName.SelectedValue = selectRow.Cells[2].Text;
****//this is giving me error****
答案 0 :(得分:1)
选择的值不能以这种方式工作。试试这个:
ddEquipmentName.SelectedIndex = ddEquipmentName.Items.IndexOf(ddEquipmentName.Items.FindByText(selectRow.Cells[2].Text));
答案 1 :(得分:0)
您可以尝试:
GridViewRow selectRow = MyGridView.SelectedRow;
ddEquipmentName.selectedItem.Text = selectRow.Cells[2].Text;
答案 2 :(得分: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));**
}
}