Hi,
I have three GridDropDownColumns in my Radgrid:
What I want to do is when in edit mode, when the selection of Country or ProvinceState dropdown change, the datasource of the sub dropdowns change. What I tried is this:
the tables are retrieved correctly, but when I do databind for the dropdown, it doesn't bind with the new tables, still bind with the old ones.
Can I get some help for this?
Thanks
I have three GridDropDownColumns in my Radgrid:
<
telerik:GridDropDownColumn
UniqueName
=
"AddressCountry"
ListDataMember
=
"AddressCountry"
ColumnEditorID
=
"AddressCountryColumnEditor"
HeaderStyle-Width
=
"200"
SortExpression
=
"Id"
ListTextField
=
"Name"
ListValueField
=
"Id"
HeaderText
=
"Country"
DataField
=
"CountryId"
/>
<
telerik:GridDropDownColumn
UniqueName
=
"AddressProvinceState"
ListDataMember
=
"AddressProvinceState"
ColumnEditorID
=
"AddressProvinceStateColumnEditor"
HeaderStyle-Width
=
"200"
SortExpression
=
"Id"
ListTextField
=
"Name"
ListValueField
=
"Id"
HeaderText
=
"Province/State"
DataField
=
"ProvinceStateId"
/>
<
telerik:GridDropDownColumn
UniqueName
=
"AddressCity"
ListDataMember
=
"AddressCity"
ColumnEditorID
=
"AddressCityColumnEditor"
HeaderStyle-Width
=
"200"
SortExpression
=
"Id"
ListTextField
=
"Name"
ListValueField
=
"Id"
HeaderText
=
"City"
DataField
=
"CityId"
/>
What I want to do is when in edit mode, when the selection of Country or ProvinceState dropdown change, the datasource of the sub dropdowns change. What I tried is this:
protected void grid_GridItemCreated(object sender, GridItemEventArgs e)
{
if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode))
{
GridEditableItem edititem = (GridEditableItem)e.Item;
int LocationId = Convert.ToInt32(edititem.GetDataKeyValue("LocationId"));
DataSet dsAddress = somefunction(LocationId);
list1.DataSource = dsAddress.Tables["AddressProvinceState"];
list1.DataTextField = "Name";
list1.DataValueField = "Id";
list1.DataBind();
RadComboBox list2 = (RadComboBox)edititem["AddressCity"].Controls[0];
list2.DataSource = dsAddress.Tables["AddressCity"];
list2.DataTextField = "Name";
list2.DataValueField = "Id";
list2.DataBind();
list.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(list_SelectedIndexChanged);
list.AutoPostBack = true;
list1.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(list1_SelectedIndexChanged);
list1.AutoPostBack = true;
}
}
private void list_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
RadComboBox list = (RadComboBox)sender;
GridDataItem editItem = (GridDataItem)list.NamingContainer;
GridEditManager editMan = editItem.EditManager;
GridDropDownListColumnEditor editor1 = editMan.GetColumnEditor("AddressProvinceState") as GridDropDownListColumnEditor;
GridDropDownListColumnEditor editor2 = editMan.GetColumnEditor("AddressCity") as GridDropDownListColumnEditor;
DataTable dtProvinceState = ProvinceForCountry(Convert.ToInt32(list.SelectedValue));
DataTable dtCity = CityForProvince(Convert.ToInt32(dtProvinceState.Rows[0]["Id"]));
editor1.DataSource = dtProvinceState;
editor1.DataTextField = "Name";
editor1.DataValueField = "Id";
editor1.DataBind();
editor2.DataSource = dtCity;
editor2.DataTextField = "Name";
editor2.DataValueField = "Id";
editor2.DataBind();
}
private void list1_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
RadComboBox list = (RadComboBox)sender;
GridEditFormItem editItem = (GridEditFormItem)list.NamingContainer;
GridEditManager editMan = editItem.EditManager;
GridDropDownListColumnEditor editor = editMan.GetColumnEditor("AddressCity") as GridDropDownListColumnEditor;
DataTable dtCity = CityForProvince (Convert.ToInt32(list.SelectedValue));
editor.DataSource = dtCity;
editor.DataTextField = "Name";
editor.DataValueField = "Id";
editor.DataBind();
}
Can I get some help for this?
Thanks