Foros del Web » Programación para mayores de 30 ;) » .NET »

Convertir código Vb.net a C#

Estas en el tema de Convertir código Vb.net a C# en el foro de .NET en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 08/10/2003, 13:00
 
Fecha de Ingreso: abril-2003
Mensajes: 606
Antigüedad: 21 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.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 17:16.