Click here to Skip to main content
15,991,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All

I have DataGridviewComboBox column in my Grid.
I am able to save the value. There is no issues.
When i rerieve from database and assign it to combobox, the datasource assigned to combox box does not display properly.

For Example

GroupId 1
Group Name Asia

And it is bound to Combox.Datasource Property.
ValueMember is GroupId
Display Member is Asia.

And i save 1 in database.
In edit mode i retrieve 1 and assign to combo like ((DataGridViewComboboxcolumn).datagrid.Rows[i].cells[0].value=1;

The combo has to display Asia in the combo in the grid.
Rather it displays 1 in the combo.

I have handled DataError of Grid Event too.

Can anyone help me to resolve the problem.
Posted

1 solution

Try this way in RowDataBound event it should work

protected void grdTourPricing_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddlBranch = e.Row.FindControl("ddlBranch") as DropDownList;

ddlBranch.DataSource = CacheMaster.getBranches();
ddlBranch.DataTextField = "BranchName";

ddlBranch.DataValueField = "BranchID";
ddlBranch.DataBind();

ddlBranch.SelectedValue = "1";

}
}
 
Share this answer
 
Comments
froxy 26-Sep-13 11:00am    
There is no event like RowDataBound
froxy 28-Sep-13 2:25am    
I am working in VS 2010 DataGridview. This is windows application. There is no event like RowDatabound in the grid

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900