conseguir índice de la fila seleccionada de la lista dinámica de selección desplegable
-
06-09-2019 - |
Pregunta
Sé que la pregunta es un poco revuelto y quizás engañosa, pero tengo un gridview con dropdownlists en las filas. He creado una AddHandler y un delegado para la SelectedIndexChanged y que llega a la sub. Aquí está el código para que:
AddHandler ddlmgr.SelectedIndexChanged, AddressOf ddlmgr_SelectedIndexChanged
Public Delegate Sub DropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As DropDownList_SelectedIndexChanged)
Protected Sub ddlmgr_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
End Sub
¿Cómo puedo obtener el ID de la fila si GridView_RowCommand no se llama?
Solución
Gran trabajo Funciona absolutamente bien para mí
DropDownList ddl = (DropDownList)sender;
Control p = ddl.Parent;
//you are going to loop because the immediate
//parent may not be the repeater item but instead a
//container control of some kind (say a template)
while (p.GetType() != typeof(RepeaterItem))
{
p = p.Parent;
if (p == null)
return; //we have reached the top of the control tree
}
RepeaterItem ri = (RepeaterItem)p;
int index = ri.ItemIndexreturn index;
Otros consejos
Usted tendrá que hacer un poco del trabajo de campo como yo puedo proporcionar el 100% específicos sin tener que escribir el código y probar por mi cuenta aquí, que no soy capaz de hacer en la actualidad, pero el código debe ir a lo largo de estas líneas .
dentro de la ddlmgr_SelectedIndexChaged,
- emitir su emisor a un DropDownList
- Acceso a la propiedad parte de la lista desplegable.
- Compruebe que es un GridItem (o RepeaterItem o el que sea, se entiende la idea)
- Si es así, obtener los elementos ItemIndex. Si no accede a su propiedad principal.
- Continuar hasta que encuentre su objeto de fila.
Esperemos que esto ayuda. Si no es así, tal vez alguien con acceso a un poco más liberal pueda intervenir
DropDownList ddl = (DropDownList)sender;
Control p = ddl.Parent;
//you are going to loop because the immediate
//parent may not be the repeater item but instead a
//container control of some kind (say a template)
while (p.GetType() != typeof(RepeaterItem))
{
p = p.Parent;
if (p == null) return; //we have reached the top of the control tree
}
RepeaterItem ri = (RepeaterItem)p;
int index = ri.ItemIndex
return index;
DropDownList ddltxt = (DropDownList) remitente; cadena temp2 = ddltxt.SelectedItem.Text; cadena TEMP3 = ddltxt.SelectedItem.Value; string temp = ddltxt.ID.ToString (); int strlength = temp.Length; cadena strLastchar = temp.Substring (strlength - 1, 1); int intlastchar = int.Parse (strLastchar.ToString ()); cadena commonpart = temp.Substring (0, strlength - 1);
if (intlastchar == 1)
{
string targetdropdownid = commonpart + "2";
DropDownList targetlist = (DropDownList)TableRow11.FindControl(targetdropdownid);
using (conn = new SqlConnection(ConnectionString))