Hi,
I'm trying to add/edit some data in a GridView and need to access the SelectedValue of a drop downlist that is in the grid.
My code is this:
GridViewRow gvRow = this.grdPhones.Rows[e.RowIndex];
Guid PhoneType = new Guid(((DropDownList)(gvRow.Cells[1].Controls[0])).SelectedValue.ToString());
And the error I get is this:
System.InvalidCastException was unhandled by user code
Message="Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.DropDownList'."
Source="SamaanSystems.IAS.Web"
StackTrace:
at SamaanSystems.IAS.Web.ClientEdit.grdPhones_RowUpdating(Object sender, GridViewUpdateEventArgs e) in C:\Development\Mere Mortals .NET Framework 2008\SamaanSystems\IAS.Web\ClientEdit.aspx.cs:line 528
at System.Web.UI.WebControls.GridView.OnRowUpdating(GridViewUpdateEventArgs e)
at System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32 rowIndex, Boolean causesValidation)
at System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup)
at System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e)
at OakLeaf.MM.Main.Web.UI.WebControls.mmGridView.OnBubbleEvent(Object source, EventArgs e)
at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
at System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e)
at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
at System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e)
at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:
This shouldn't be so hard :(