1

代码

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****
4

3 回答 3

1

所选值不能以这种方式工作。尝试这个:

ddEquipmentName.SelectedIndex = ddEquipmentName.Items.IndexOf(ddEquipmentName.Items.FindByText(selectRow.Cells[2].Text));
于 2013-08-14T00:31:24.843 回答
0

你可以试试 :

GridViewRow selectRow = MyGridView.SelectedRow;    
ddEquipmentName.selectedItem.Text = selectRow.Cells[2].Text;
于 2013-08-14T06:12:16.947 回答
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));**
    }
}
于 2013-08-14T11:00:53.513 回答