DataGridviewComboBox列未正确显示该值 [英] DataGridviewComboBox column does not display the value properly
问题描述
大家好
我的网格中有DataGridviewComboBox列。
我可以保存该值。没有问题。
当我从数据库中恢复并将其分配给组合框时,分配给combox框的数据源无法正常显示。
例如
GroupId 1
团体名称亚洲
和它绑定到Combox.Datasource属性。
ValueMember是GroupId
显示会员是亚洲。
和我在数据库中保存1.
在编辑模式下,我检索1并分配给组合(如(DataGridViewComboboxcolumn).datagrid.Rows [i] .cells [0] .value = 1;
组合必须在网格中的组合中显示亚洲。
而是在组合中显示1。
我也处理了Grid Event的DataError。
任何人都可以帮我解决问题。
在RowDataBound事件中尝试这种方式它应该工作
protected void grdTourPricing_RowDataBound(o bject sender,GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddlBranch = e.Row.FindControl(ddlBranch)作为DropDownList;
ddlBranch.DataSource = CacheMaster.getBranches();
ddlBranch.DataTextField =BranchName;
ddlBranch.DataValueField =BranchID;
ddlBranch.DataBind(); < br $> b $ b
ddlBranch.SelectedValue =1;
}
}
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.
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";
}
}
这篇关于DataGridviewComboBox列未正确显示该值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!