احصل على مؤشر الصف المحدد للاختيار قائمة المنسدلة الديناميكية

StackOverflow https://stackoverflow.com/questions/928131

سؤال

أعلم أن السؤال متقطع قليلا وربما مضللة، لكن لدي GridView مع أرض سرعات على الصفوف. لقد أنشأت Addhandler و Modult for the shildindexchanged واتصل إلى الفرعية. هنا هو الرمز لذلك:

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؟

هل كانت مفيدة؟

المحلول

عمل رائع يعمل بشكل جيد للغاية بالنسبة لي

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_SELDECTEDEDEXCHAGER،

  1. يلقي المرسل الخاص بك إلى القائمة المنسدلة
  2. الوصول إلى خاصية الجزء من القائمة المنسدلة.
  3. تحقق من ذلك هو Griditem (أو repeteritem أو أيهما، يمكنك الحصول على الفكرة)
  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;

HorpDownList DDLTXT = (القائمة المنسدلة) المرسل؛ String Temp2 = ddltxt.selectedItem.text؛ String Temp3 = ddltxt.seletitim.value؛ سلسلة temp = ddltxt.id.tostring ()؛ int strlength = temp.length؛ سلسلة strlastchar = temp.substring (strlength - 1، 1)؛ int intlastchar = int.parse (strlastchar.toststring ())؛ سلسلة commentpart = 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