Hi,
I'm trying to setup a DataGridView with ComboBox, but I can't manage to setup the selected value of the combobox.
The ComboBox value & display members are from table[1] of a Dataset
object, and the rest of the datagrid columns are from Table[0] of the
dataset. "noseID" (the primary key in Table[1] and the foreign key in
Table[0]). How do I apply a selected value for the combobox? Here's my
code:
{
this.Controls.Add(afikimGrid);
DataGridViewComboBoxColumn comboGrid = new DataGridViewComboBoxColumn();
comboGrid.DataSource = dsRisk.Tables[1];
comboGrid.DisplayMember = "NoseDesc";
comboGrid.ValueMember = "NoseID";
afikimGrid.DataSource = dsRisk.Tables[0];
afikimGrid.Columns.Add(comboGrid);
}
Thanks,
Udi
Loading
Manikavelu VelayuthamPosted Aug 30, 2010, 3:30 AM
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView drv=e.Row.DataItem as DataRowView ;
String City=drv["City"].ToString();
DropDownList ddl=(DropDownList)e.Row.FindControl("ddlCity");
ddl.DataSource=dtCities;
ddl.DataTextField="City";
ddl.DataBind();
ddl.Items.FindByText(City).Selected=true;
}
}
Note: If this post really helped you, mark this answer as Accepted.