gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 02:23:33 25 4
gpt4 key购买 nike

我想找到父转发器,其中包含子转发器和子转发器包含下拉列表。在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com