문제

나는 질문이 약간 고르지 않고 오도 될 수 있다는 것을 알고 있지만, 줄에 드롭 다운 목록이있는 그리드 뷰가 있습니다. 선택한 indexChanged에 대한 addhandler와 대의원을 만들었고 서브에 도달했습니다. 다음은 다음과 같은 코드입니다.

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

gridview_rowcommand가 호출되지 않은 경우 행의 ID를 얻으려면 어떻게해야합니까?

도움이 되었습니까?

해결책

훌륭한 일은 저에게 절대적으로 잘 작동합니다

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;

다른 팁

코드를 작성하지 않고 여기에서 자신의 테스트하지 않고 100% 구체적인 내용을 제공 할 수 없으므로 약간의 레그 워크를 수행해야합니다. 현재 코드는 할 수 없지만 코드는이 라인을 따라 가야합니다.

ddlmgr_selectedIndExchaged 내에서

  1. 발신자를 드롭 다운리스트로 캐스팅하십시오
  2. 드롭 다운 목록의 부품 속성에 액세스하십시오.
  3. 검사는 그리드디템 (또는 리피터 리티 또는 아이디어를 얻는 것)인지 확인하십시오.
  4. 그렇다면 항목 itemindex를 받으십시오. 부모 속성에 액세스하지 않으면
  5. 행 개체를 찾을 때까지 계속하십시오.

바라건대 이것은 도움이됩니다. 그렇지 않다면 아마도 더 자유로운 접근을 가진 사람은

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) 발신자; 문자열 temp2 = ddltxt.selecteditem.text; 문자열 temp3 = ddltxt.selectedItem.Value; 문자열 temp = ddltxt.id.toString (); int Strlength = temp.length; 문자열 strlastchar = temp.substring (strlength -1, 1); int intlastchar = int.parse (strlastchar.tostring ()); 문자열 commonPart = temp.SubString (0, Strlength -1);

    if (intlastchar == 1)
    {
        string targetdropdownid = commonpart + "2";
        DropDownList targetlist = (DropDownList)TableRow11.FindControl(targetdropdownid);
        using (conn = new SqlConnection(ConnectionString))
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top