Pergunta

Eu sei que a questão é um pouco agitado e talvez enganosa, mas eu tenho um gridview com dropdownlists sobre as linhas. Criei um AddHandler e um delegado para o SelectedIndexChanged e se chega ao sub. Aqui está o código para isso:

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

Como posso obter Id da linha se GridView_RowCommand não é chamado?

Foi útil?

Solução

Great trabalho Funciona absolutamente bem para mim

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;

Outras dicas

Você precisará fazer um pouco de trabalho braçal como eu não posso fornecer 100% especificidades sem escrever o código e testá-lo em meu próprio aqui, que eu sou incapaz de fazer no momento, mas o código deve ir ao longo destas linhas .

dentro do ddlmgr_SelectedIndexChaged,

  1. lançar o seu remetente para um DropDownList
  2. Acesso a propriedade parte do dropdownlist.
  3. Verifique é um GridItem (ou RepeaterItem ou qualquer, você começa a idéia)
  4. Se for assim, obter os itens ItemIndex. Se não acessar sua propriedade pai.
  5. Continue até encontrar o seu objeto Row.

Esperemos que esta ajuda. Se não, talvez alguém com acesso um pouco mais liberal pode carrilhão em

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) remetente; corda temp2 = ddltxt.SelectedItem.Text; corda TEMP3 = ddltxt.SelectedItem.Value; Temp = cadeia ddltxt.ID.ToString (); int strlength = temp.Length; cadeia strLastchar = temp.Substring (strlength - 1, 1); int intlastchar = int.Parse (strLastchar.ToString ()); corda commonpart = temp.Substring (0, strlength - 1);

    if (intlastchar == 1)
    {
        string targetdropdownid = commonpart + "2";
        DropDownList targetlist = (DropDownList)TableRow11.FindControl(targetdropdownid);
        using (conn = new SqlConnection(ConnectionString))
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top