Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/10/2003, 13:00
DotNetDeveloper
 
Fecha de Ingreso: abril-2003
Mensajes: 606
Antigüedad: 22 años
Puntos: 2
Convertir código Vb.net a C#

Public Sub SetDropDownIndex(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim ed As System.Web.UI.WebControls.DropDownList
ed = sender
ed.SelectedIndex = ed.Items.IndexOf(ed.Items.FindByText(strCountry))
End Sub

Quiero pasarlo a C#

Lo que hace es que selecciona un valor de un DDL de un registro editable de
un datagrid

http://www.dotnetjohn.com/articles/articleid21.aspx

Al pasarlo a C#:

private void dgNumero_PreRender(object sender, System.EventArgs e)
{
System.Web.UI.WebControls.DropDownList ed;
ed= (System.Web.UI.WebControls.DropDownList)sender;
ed.SelectedIndex =
ed.Items.IndexOf(ed.Items.FindByValue(ddlCategoria .SelectedItem.Value));
}

Pero o sorpresa me dice que el casting no esta bien

Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Specified cast is not valid.