如何找到repeter中HeaderTemplate里面的控件!紧急呼救!!!~~~~~
我要找到HeaderTemplate里面的控件,给此控件附值,但怎么也找不到控件,寻求高手帮助!,,,
部分代码为:
<asp:Repeater ID= "DataList1 " runat= "server " OnItemDataBound= "DataList1_ItemDataBound ">
<HeaderTemplate>
<table width= "100% " border= "1 " bordercolor= "#000000 " style= "border-collapse:collapse " cellspacing= "0 " cellpadding= "0 ">
<tr>
<td runat= "server " id= "td0 " height= "22 "> 会员名称 </td>
<td runat= "server " id= "td1 "> <asp:Label ID= "lblScore1 " runat= "server " Text= "Label " Width= "150% "> </asp:Label> </td>
<td runat= "server " id= "td2 "> <asp:Label ID= "lblScore2 " runat= "server " Text= "Label " Width= "150% "> </asp:Label> </td>
<td runat= "server " id= "td3 "> <asp:Label ID= "lblScore3 " runat= "server " Text= "Label " Width= "150% "> </asp:Label> </td>
<td runat= "server " id= "td4 "> <asp:Label ID= "lblScore4 " runat= "server " Text= "Label " Width= "150% "> </asp:Label> </td>
<td runat= "server " id= "td5 "> <asp:Label ID= "lblScore5 " runat= "server " Text= "Label " Width= "150% "> </asp:Label> </td>
<td runat= "server " id= "td6 "> <asp:Label ID= "lblScore6 " runat= "server " Text= "Label " Width= "150% "> </asp:Label> </td>
<td runat= "server " id= "td7 "> <asp:Label ID= "lblScore7 " runat= "server " Text= "Label " Width= "150% "> </asp:Label> </td>
<td runat= "server " id= "td8 "> <asp:Label ID= "lblScore8 " runat= "server " Text= "Label " Width= "150% "> </asp:Label> </td>
<td runat= "server " id= "td9 "> <asp:Label ID= "lblScore9 " runat= "server " Text= "Label " Width= "150% "> </asp:Label> </td>
<td runat= "server " id= "td10 "> <asp:Label ID= "lblScore10 " runat= "server " Text= "Label " Width= "150% "> </asp:Label> </td>
<td> <asp:Label ID= "lblBonusNum " runat= "server " Text= "Label " Width= "150% "> </asp:Label> </td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
***************
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
CS文件部分代码为:
public void DataListBind()
{
SiteConfigurations objSiteConfigurations = new SiteConfigurations();
SiteConfiguration objSiteConfiguration = objSiteConfigurations.GetSiteConfiguration()[0];
Label lb1 = (Label)DataList1.Controls[0].FindControl( "lblScore1 ");
HtmlTableCell objHTCell = null;
if (lb1 != null)
{
string[] EnabledBonus = BonusGroupSplit(objSiteConfiguration.UserBonus);
for (int i = 0; i < EnabledBonus.Length - 1; i++)
{
int index = i + 1;
string[] BonusItemArray = BonusItemSplit(EnabledBonus[i]);
if (BonusItemArray[3] == "1 ")
{
lb1 = (Label)DataList1.Controls[0].FindControl( "lblScore " + index.ToString());
lb1.Text = BonusItemArray[0].ToString();
continue;
}
if (BonusItemArray[3] == "0 ")
{
objHTCell = (HtmlTableCell)DataList1.Controls[0].FindControl( "td " + index.ToString());
objHTCell.Visible = false;
}
}
}
}
可是找不到控件 报的错为:
Specified argument was out of the range of valid values.
Parameter name: index
指定为Line 107: Label lb1 = (Label)DataList1.Controls[0].FindControl( "lblScore1 ");
这句找不到
[解决办法]
foreach (RepeaterItem item in DataList1.Controls)
{
if (item.ItemType == ListItemType.Header)
{
Label lbl = item.FindControl( "lblScore1 ") as Label;
// lbl.Text =
// .....
break;
}
}
[解决办法]
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Header)
{
SiteConfigurations objSiteConfigurations = new SiteConfigurations();
SiteConfiguration objSiteConfiguration = objSiteConfigurations.GetSiteConfiguration()[0];
Label lb1 = (Label) e.Item.FindControl( "lblScore1 ");
HtmlTableCell objHTCell = null;
if (lb1 != null)
{
string[] EnabledBonus = BonusGroupSplit(objSiteConfiguration.UserBonus);
for (int i = 0; i < EnabledBonus.Length - 1; i++)
{
int index = i + 1;
string[] BonusItemArray = BonusItemSplit(EnabledBonus[i]);
if (BonusItemArray[3] == "1 ")
{
lb1 = (Label) e.Item.FindControl( "lblScore " + index.ToString());
lb1.Text = BonusItemArray[0].ToString();
continue;
}
if (BonusItemArray[3] == "0 ")
{
objHTCell = (HtmlTableCell) e.Item.FindControl( "td " + index.ToString());
objHTCell.Visible = false;
}
}
}
}
}