I am trying to implement Cascading Dropdown list in GridView in Edit mode.
The code is VB and working as desired. However I am stuck while converting this Code in C#.
Getting compilation error 'CS0266: Cannot implicitly convert type 'object' to 'System.Data.DataRowView'. An explicit conversion exists (are you missing a cast?)'.
Please help.
<script runat="server">
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
DropDownList listManufacturers = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("listManufacturers");
DropDownList listModels = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("listModels");
e.NewValues["Manufacturer"] = listManufacturers.SelectedValue;
e.NewValues["Model"] = listModels.SelectedValue;
}
protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
if (((e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit))
{
System.Data.DataRowView dv = e.Row.DataItem;
DropDownList listManufacturers = e.Row.FindControl("listManufacturers");
listManufacturers.SelectedValue = dv("Manufacturer");
DropDownList listModels = e.Row.FindControl("listModels");
SqlDataSource dsc = e.Row.FindControl("dsModelsByManufacturer");
dsc.SelectParameters("Manufacturer").DefaultValue = dv["Manufacturer"];
listModels.DataBind();
listModels.SelectedValue = dv("Model");
}
}
protected void listManufacturers_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList listManufacturers, listModels;
SqlDataSource dsModelsByManufacturer;
int currentRowInEdit = GridView1.EditIndex;
listManufacturers = (DropDownList)sender;
listModels = (DropDownList)GridView1.Rows[currentRowInEdit].FindControl("listModels");
dsModelsByManufacturer = (SqlDataSource)GridView1.Rows[currentRowInEdit].FindControl("dsModelsByManufacturer");
dsModelsByManufacturer.SelectParameters["Manufacturer"].DefaultValue = listManufacturers.SelectedValue;
listModels.DataBind();
}
</script>