Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Get SelectedValue from dropdownlist in GridView
Message
From
16/03/2010 04:22:42
 
 
To
15/03/2010 18:23:57
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01454691
Message ID:
01454710
Views:
28
>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 :(

The line looks right (there's an unneccessary pair of brackets - but no harm in that). The obvious implication is that 'gvRow.Cells[1].Controls[0]' is not actually a DropDownList ?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform