我有一個webform,它動態加載一個web用戶控件。在Web用戶控件內部是一箇中繼器控件,並且可以根據需要在其中自動創建Web用戶控件,並將所有這些控件加載到佔位符中。循環通過窗體上的控件始終獲得第一個控件
如:
webusercontrol1
repeater
webusercontrol
repeater
webusercontrol
repeater
webusercontrol
repeater
當我遍歷佔位符中的控件,在出現的唯一的中繼器是第一個中繼器。
我的代碼如下:
protected void cmdsave_Click(object sender, EventArgs e)
{
foreach (Control ctl in this.officephld.Controls)
{
if (ctl.GetType().ToString() == "ASP.evalctl_ascx")
{
foreach (Control sctl in ctl.Controls)
{ GetRatingControl(sctl); }
}
}
Response.Redirect("~/contractoreval.aspx?sc=1");
}
protected void GetRatingControl(Control item)
{
Repeater rpt = (Repeater)item.FindControl("rptPts");
foreach (Control ctl in rpt.Controls)
{
if (ctl.GetType().ToString() == "System.Web.UI.WebControls.RepeaterItem")
{
RepeaterItem ri = (RepeaterItem)ctl;
HiddenField pntid = (HiddenField)ri.FindControl("pntid");
HiddenField catid = (HiddenField)ri.FindControl("catid");
HiddenField rating = (HiddenField)ri.FindControl("rating");
if (pntid != null && catid != null)
{
AjaxControlToolkit.Rating rtg = (AjaxControlToolkit.Rating)ri.FindControl("pntrating");
SQLConnectivity db = new SQLConnectivity();
SqlParameter[] param = new SqlParameter[8];
int iRetValue = 0;
param[0] = db.MakeInputParameter("@eval_id", Convert.ToInt32(pntid.Value));
param[1] = db.MakeInputParameter("@category_id", Convert.ToInt32(catid.Value));
param[2] = db.MakeInputParameter("@organization_id", 1);
param[3] = db.MakeInputParameter("@subcontractor_id", 1);
param[4] = db.MakeInputParameter("@project_id", 1);
param[5] = db.MakeInputParameter("@rating", Convert.ToInt32(rating.Value));
param[6] = db.MakeInputParameter("@created_by", 1);
param[7] = db.MakeInputParameter("@updated_by", 1);
db.RunNonQueryProcedure("PerformanceSubcontractorEvalSave", param, ref iRetValue);
}
}
}
}
編輯 該轉發器,這hiddenfield評級僅被instatiated第一重複控制,下面是我的HTML標記:
<asp:Repeater ID="rptPts" runat="server" Visible="false"
onitemdatabound="rptPts_ItemDataBound">
<HeaderTemplate></HeaderTemplate>
<ItemTemplate>
<div style="width:75%;float:left;padding-top:3px;height:20px;">
<asp:Label runat="server" ID="Label1" Text='<%#DataBinder.Eval(Container.DataItem, "eval_description") %>' Font-Names="Arial" Font-Size="10px"></asp:Label>
</div>
<asp:HiddenField ID="catid" runat="server" />
<asp:HiddenField ID="pntid" runat="server" />
<asp:HiddenField ID="rating" runat="server" />
<div style="width:20%;float:right;padding-top:3px;padding-bottom:3px;height:20px;">
<cc1:Rating ID="pntrating" runat="server" FilledStarCssClass="filldStar" OnChanged="pntrating_Changed" EmptyStarCssClass="emptyStar" StarCssClass="filldStar" WaitingStarCssClass="savedStar" EnableViewState="true" AutoPostBack="false" BehaviorID="ratingControlBehavior">
</cc1:Rating>
</div>
<div style="clear:both;"></div>
</ItemTemplate>
<FooterTemplate></FooterTemplate>
</asp:Repeater>
我該如何循環通過中繼器控制的各個級別並獲得此設置中的中繼器項目?
我在想這樣做遞歸,但我被陷在何處執行遞歸。 – mattgcon
在foreach循環中。 – kmcc049
好吧,現在確實是在那個循環內部的IF語句中還是在它之後呢? – mattgcon