Asp.net 从子中继器中查找父中继器';s dropdownlist selectedindexchange

Asp.net 从子中继器中查找父中继器';s dropdownlist selectedindexchange,asp.net,repeater,Asp.net,Repeater,我想找到父中继器,它包含子中继器,子中继器包含dropdownlist。在选择DexChange of the downlist时,我想找出父中继器。找到父中继器后,我想在父中继器内找到hiddenfield值。i、 e 父中继器包含HiddenField和子中继器 子中继器包含此下拉列表上的Dropdownlist selected index change事件我想查找父中继器中的HiddenField值 我的代码: DropDownList myGeneralButton =

我想找到父中继器,它包含子中继器,子中继器包含dropdownlist。在选择DexChange of the downlist时,我想找出父中继器。找到父中继器后,我想在父中继器内找到hiddenfield值。i、 e

父中继器包含HiddenField和子中继器 子中继器包含此下拉列表上的Dropdownlist selected index change事件我想查找父中继器中的HiddenField值

我的代码:

        DropDownList myGeneralButton = (DropDownList)sender;
        Repeater item = (Repeater)myGeneralButton.Parent.Parent;

        for (int i = 0; i < item.Items.Count; ++i) 
        {
            HiddenField hdn=  item.Items[i].FindControl("Hdhotelname") as HiddenField;
            string h = hdn.Value;
        }
DropDownList myGeneralButton=(DropDownList)发送方;
中继器项=(中继器)myGeneralButton.Parent.Parent;
对于(int i=0;i
在这个隐藏字段中,我得到了所有的值,但是我想要一个我选择下拉列表的特定索引的值

谢谢


或者直接在代码隐藏中使用它,而不使用



或者直接在代码隐藏中使用它,而不使用

您必须通过
下拉列表
NamingContainer
进行搜索。流程应该是这样的:

(下拉列表)发送方
-->NamingContainer(子RepeaterItem)
-->NamingContainer(子中继器)
-->NamingContainer(父RepeaterItem)
-->FindControl“Hdhotelname”(Hdhotelname)

您的代码应该是这样的:

protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
    var ddl = (DropDownList)sender;
    var rptChild = ddl.NamingContainer.NamingContainer;//Child Repeater
    if (rptChild != null)
    {
        var rptParentItem = rptChild.NamingContainer;//Parent RepeaterItem
        var hdnfld = rptParentItem.FindControl("Hdhotelname") as HiddenField;
        if (hdnfld != null)
        {
            //Do your tasks
        }
    }
}

希望有帮助

您必须在
DropDownList
NamingContainer
中进行搜索。流程应该是这样的:

(下拉列表)发送方
-->NamingContainer(子RepeaterItem)
-->NamingContainer(子中继器)
-->NamingContainer(父RepeaterItem)
-->FindControl“Hdhotelname”(Hdhotelname)

您的代码应该是这样的:

protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
    var ddl = (DropDownList)sender;
    var rptChild = ddl.NamingContainer.NamingContainer;//Child Repeater
    if (rptChild != null)
    {
        var rptParentItem = rptChild.NamingContainer;//Parent RepeaterItem
        var hdnfld = rptParentItem.FindControl("Hdhotelname") as HiddenField;
        if (hdnfld != null)
        {
            //Do your tasks
        }
    }
}

希望有帮助

谢谢你的回复。我做到了:DropDownList myGeneralButton=(DropDownList)sender;RepeaterItem=(RepeaterItem)myGeneralButton.Parent.Parent;我还想找出中继器中的隐藏字段你能帮助我吗HiddenField在父中继器中,我想找到该值(HiddenField)((RepeaterItem)NestedRepeater.Parent.Parent)。FindControl(“HiddenInputFieldDidinParent”);如果您没有在Item_数据绑定事件中执行此操作。。。然后需要将(int i=0;i