ottenere l'indice di riga selezionata di selezione a discesa dinamico
-
06-09-2019 - |
Domanda
So che la questione è un po 'mosso e forse fuorviante, ma ho una GridView con DropDownList sulle righe. Ho creato un AddHandler e un delegato per la SelectedIndexChanged e si arriva al sub. Ecco il codice per questo:
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
Come posso ottenere l'ID della riga se GridView_RowCommand non si chiama?
Soluzione
Gran lavoro Funziona assolutamente bene per me
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;
Altri suggerimenti
Sarà necessario fare un po 'di noia, come non posso fornire il 100% specifiche senza scrivere il codice e test per conto mio qui, che non sono in grado di fare al momento, ma il codice dovrebbe andare in questa direzione .
all'interno del ddlmgr_SelectedIndexChaged,
- Cast vostra mittente di un DropDownList
- l'accesso alla proprietà parte del dropdownlist.
- Controlla è un GridItem (o repeateritem o qualsiasi, si ottiene l'idea)
- Se è così, ottenere gli elementi ItemIndex. Se non accede la proprietà Parent.
- Continua fino a trovare l'oggetto Row.
Speriamo che questo aiuta. In caso contrario, forse qualcuno con un po 'di più l'accesso liberale può carillon
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) del mittente; stringa temp2 = ddltxt.SelectedItem.Text; stringa TEMP3 = ddltxt.SelectedItem.Value; Temp stringa = ddltxt.ID.ToString (); int = strlength temp.Length; stringa strLastchar = temp.Substring (strlength - 1, 1); int = intlastchar int.Parse (strLastchar.ToString ()); stringa commonpart = temp.Substring (0, strlength - 1);
if (intlastchar == 1)
{
string targetdropdownid = commonpart + "2";
DropDownList targetlist = (DropDownList)TableRow11.FindControl(targetdropdownid);
using (conn = new SqlConnection(ConnectionString))