Problems with Dropdownlist in EditMode in nested gridview

F

Fabrizio

Hi all.
I have a field in a gridview as templatefield which is a label in view mode
and a dropdownlist in edit mode with his datasource.
This gridview is inserted as templatefield in another mother gridview.

GRIDVIEW1
[key field] - [gridview2]

GRIDVIEW2
[templatefiled] [other fields]

TEMPLATEFIELD
- edit mode - dropdownlist
- view mode - label

In the evetn GRIDVIEW2_rowUpdating i need to assign key and value of
dropdownlist to my memory datatable fileds.
This is the code

protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs
e)
{
GridView GridView2 = (GridView)sender;
GridViewRow currRow = GridView2.Rows[e.RowIndex];
GridView2.EditIndex = e.RowIndex;
Label grnLabel = (Label)GridView2.Parent.FindControl("Codice_giorno");
string grnId = grnLabel.Text; //cella del parametro grn_id
Ds_Rapporto.Tables["Attivita"].DefaultView.RowFilter = "ATT_GRN='" + grnId
+ "'";
DataRow currDr =
((DataView)GridView2.DataSource)[Convert.ToInt32(e.RowIndex)].Row;
DropDownList listaCommesse = (DropDownList)currRow.FindControl("Commessa");
currDr["ATT_COMMESSA_ID"] = Convert.ToInt32(listaCommesse.SelectedValue);
currDr["ATT_COMMESSA"] = listaCommesse.SelectedItem.Text;
....
}

THE ERROR IS THIS
"System.InvalidCastException was unhandled by user code
Message="Unable to cast object of type 'System.Web.UI.WebControls.Label'
to type 'System.Web.UI.WebControls.DropDownList'."

The problem is that the application consider the label instead of the
dropdownlist?
Anyone can explain me how can i refer to the dropdownlist?
Thanks
Fabrizio
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top