asp.net - 从子转发器的下拉列表中找到父转发器 selectedindexchange

标签 asp.net repeater

我想找到父转发器,其中包含子转发器和子转发器包含下拉列表。在 Drowndownlist 的 SelectedIndexChange 上,我想找出父转发器。找到parent repeater后,想找到Parent Repeater里面的hiddenfield value。即

Parent Repeater 包含 HiddenField 和 Child Repeater 子中继器在此下拉列表中包含下拉列表选定的索引更改事件我想找到父中继器中的 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;
        }

在这个隐藏字段中,我得到了所有的值,但我想要一个特定索引的值,我在其中选择了下拉菜单。

谢谢

最佳答案

您必须搜索 DropDownListNamingContainer。流程应该是这样的:

(DropDownList)sender
--> NamingContainer(Child RepeaterItem)
--> NamingContainer(Child Repeater)
--> NamingContainer(Parent 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
        }
    }
}

希望对您有所帮助!

关于asp.net - 从子转发器的下拉列表中找到父转发器 selectedindexchange,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21339120/

相关文章:

asp.net - 如何访问 ASP.net 中嵌套中继器内的按钮?

c# - 在 Repeater 控件中找不到标签控件

css - asp.net 页面中的谷歌地图

asp.net - IIS url重写模块中的设置规则

c# - 在 ASP.NET MVC 中通过 jQuery 提交表单时传递参数

c# - 中继器内的按钮 Onclick

c# - ASP.NET 水平转发器

asp.net - 如果在下拉列表中选择特定值,则防止回发

c# - Asp.Net C# 对象相关问题

c# - 如何安排日期时间列表的特殊表格格式