Hi guys,
I am getting this strange error and I am really pulling my hair at the moment. My scenario is simple. I have a drop down list for Categories. When the user Selects and category, I populate another drop down list of subcategory based on the selected category.
Here is the code
The problem is that ddlCategory.SelectedItem.Value statement throws exception, Unable to cast object of type 'System.Data.DataRowView' to type 'System.IConvertible'. If i skip this function first time and change the index to some other than it works fine. Why is it not returning the SelectedValue on first bind
Thanks
Afraz Ali
I am getting this strange error and I am really pulling my hair at the moment. My scenario is simple. I have a drop down list for Categories. When the user Selects and category, I populate another drop down list of subcategory based on the selected category.
Here is the code
private
void
ddlCategory_SelectedIndexChanged(
object
sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
this
.PopulateSubCategories();
}
private
void
PopulateSubCategories()
{
DataTable dtSubCategories =
new
SubCategory().GetSubCategoryByCategoryID(Convert.ToInt64(ddlCategory.SelectedItem.Value));
DataRow dr = dtSubCategories.NewRow();
dr[
"ID"
] = 0;
dr[
"Name"
] =
"Any"
;
dr[
"CategoryID"
] = 0;
dr[
"isACtive"
] =
true
;
dtSubCategories.Rows.InsertAt(dr, 0);
this
.ddlSubCategory.DataSource = dtSubCategories;
this
.ddlSubCategory.DisplayMember =
"Name"
;
this
.ddlSubCategory.ValueMember =
"ID"
;
this
.ddlSubCategory.SelectedIndex = 0;
}
The problem is that ddlCategory.SelectedItem.Value statement throws exception, Unable to cast object of type 'System.Data.DataRowView' to type 'System.IConvertible'. If i skip this function first time and change the index to some other than it works fine. Why is it not returning the SelectedValue on first bind
Thanks
Afraz Ali