更具体地使用以下示例, 如何使用数据列表“DL_Pro_Result”在C#中查找子数据主义者“DL_Gro_Result”?
例如,在以下代码中,dlii值为null,即使dli!= null。
DataList dli = (DataList)Page.FindControl("DL_Pro_Result");
DataList dlii = (DataList)dli.FindControl("DL_Gro_Result");
感谢。
<div id="ProList">
<asp:DataList ID="DL_Pro_Result" runat="server">
<HeaderTemplate>
<table id="T_Pro_Result_Header" runat="server">
<tr>
<td>
<asp:Label ID="L_Pro_Result_Header" runat="server"></asp:Label>
</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table id="T_Pro_Result_Item" class="table" runat="server">
<tr>
<td>
<asp:Label ID="L_Pro_Result_Item" runat="server"></asp:Label>
<asp:Button ID="B_Pro_Result_Item_1" OnClick="B_Pro_Result_Item_1_Click"/>
</td>
</tr>
<tr>
<td>
<asp:DataList ID="DL_Gro_Result" runat="server">
答案 0 :(得分:0)
解决方案:
DataList dli = (DataList)Page.FindControl("DL_Pro_Result");
foreach (Control child in dli.Controls)
{
foreach (Control child1 in child.Controls)
{
try
{
if ((DataList)child1.FindControl("DL_Gro_Result") != null)
{
DataList dli = (DataList)child1.FindControl("DL_Gro_Result");
}
}
catch (Exception e)
{
Trace.Warn("Exception!!", e.ToString() + "Trying next iteration");
}
}
}