我正在建立一个包含以下控件的页面:一个modalpopupextender和两个手风琴部分。页面的顶部将填充顶部的手风琴。它用于包含几个CheckBoxList,我用它们来过滤Accordion#2中的数据。
if (!IsPostBack)
{
DataSet ds = jdh.GetDataSetFromDB("Select GeoLocationID, GeoLocationName from geolocation order by GeoLocationName");
Locationschklst.DataSource = ds;
Locationschklst.DataTextField = "GeoLocationName";
Locationschklst.DataValueField = "GeoLocationID";
Locationschklst.DataBind();
DataSet ds1 = jdh.GetDataSetFromDB("Select PostingTypeID, PostingTypeName from PostingType where PostingTypeID >= 3 and PostingTypeID <= 10 order by PostingTypeID");
OpportunityChklst.DataSource = ds1;
OpportunityChklst.DataTextField = "PostingTypeName";
OpportunityChklst.DataValueField = "PostingTypeID";
OpportunityChklst.DataBind();
DataSet ds2 = jdh.GetDataSetFromDB("Select SalaryGradeID, SalaryGrade from SalaryGrade order by SalaryGradeID");
SalaryGradeChklst.DataSource = ds2;
SalaryGradeChklst.DataTextField = "SalaryGrade";
SalaryGradeChklst.DataValueField = "SalaryGradeID";
SalaryGradeChklst.DataBind();
DataSet ds3 = jdh.GetDataSetFromDB("Select LOBMFOID, LOBMFOAbb from LOBMFO order by LOBMFOAbb");
DisciplineChklst.DataSource = ds3;
DisciplineChklst.DataTextField = "LOBMFOAbb";
DisciplineChklst.DataValueField = "LOBMFOID";
DisciplineChklst.DataBind();
VirtualChklst.Items.Add("No");
VirtualChklst.Items.Add("Yes");
//LoadOpportunities("EXEC GetOpenPostings");
}
第二个手风琴在页面加载时动态填充。无论加载是否为回发,都会发生。我这样做是因为,如果将其放在!postback部分中,则当我在第一手风琴中选择过滤器时它不会显示。它根据返回的数据集的结果动态创建面板。每个创建的面板都有一个按钮。
protected void LoadOpportunities(string query)
{
DataSet openOpportunities_ds = jdh.GetDataSetFromDB(query);
int i = 0; // I will use this for creating unique accordion panes in each iteration of the loop
Label lblTitle; // This i will use as a child control to handle Header Text in the accordion pane
Label lblContent; // This i will use as a child control to handle Content Text in the accordion pane
UpdatePanel updpnl;
AjaxControlToolkit.AccordionPane pn; // I have declared an accordion pane but not yet initialized
foreach (DataRow dr in openOpportunities_ds.Tables[0].Rows)
{
// Begin your table
StringBuilder sb = new StringBuilder("<table>");
sb.AppendFormat("<tr><td style=\"width:150px;\"></td><td style=\"width:750px;\"></td></tr>");
sb.AppendFormat("<tr><td style=\"background-color:Yellow; font-weight:bold; text-align:right;border:solid\">{0}</td><td style=\"font-size:18px\">{1}</td></tr>", "Location:", dr["GeoLocationName"].ToString());
sb.AppendFormat("<tr><td style=\"background-color:Yellow; font-weight:bold; text-align:right;border:solid\">{0}</td><td style=\"font-size:18px\">{1}</td></tr>", "Salary Grade:", dr["SalaryGrade"].ToString());
lblTitle = new Label();
lblContent = new Label();
updpnl = new UpdatePanel();
lblTitle.Text = "ID: <b>" + dr["PostingID"].ToString() + "</b> Title: <b>" + dr["PostingTitle"].ToString() + "</b> Discipline: <b>" + dr["LOBMFOAbb"].ToString() +
"</b> Virtual: <b>" + dr["VirtualPosition"].ToString() + "</b> Opportunity Type: <b>" + dr["PostingTypeName"].ToString() + "</b>";
Button ApplyButton = new Button();
ApplyButton.ID = "Apply_" + dr["PostingID"].ToString();
ApplyButton.Text = "Apply";
ApplyButton.Click += new EventHandler(this.ApplyOpportunity);
updpnl.ContentTemplateContainer.Controls.Add(ApplyButton);
lblContent.Text = sb.ToString();
pn = new AjaxControlToolkit.AccordionPane();
pn.ID = "Pane" + dr["PostingID"].ToString();
pn.HeaderContainer.Controls.Add(lblTitle);
pn.ContentContainer.Controls.Add(lblContent);
pn.ContentContainer.Controls.Add(updpnl);
//Accordion1.Panes.Remove(pn);
Accordion1.Panes.Add(pn);
++i;
}
}
到目前为止,一切正常。我遇到的问题如下:当用户按下面板中的按钮时,应该使用包含按钮的面板中的数据填充modalpopupextender。我可以在后面的代码中获得所需的数据,但是当弹出窗口显示时,它并不会被填充。
protected void modalpopupdisplay(string OpID)
{
int i = OpID.IndexOf("_");
string opportunityid = OpID.Substring(i+1,OpID.Length - (i+1));
string title = jdh.GetSingleValueFromDB("Select PostingTitle from postings where PostingID = '" + opportunityid + "'");
title = "Apply to " + title;
TheHeader.Text = title;
ModalPopupExtender1.Show();
//Page.ClientScript.RegisterClientScriptBlock(GetType(), "scrollTop", "function scrollTop(){ window.scrollTo(0,0);} window.onload=scrollTop;", true);
}
在上面的代码中,我可以成功地构建“ title”字符串并将其分配给“ TheHeader.Text”。但是,当弹出窗口显示时,TheHeader.Text为空。
<asp:LinkButton ID="lnkDummy" runat="server"></asp:LinkButton>
<ajaxToolkit:modalpopupextender id="ModalPopupExtender1" runat="server"
okcontrolid="btnOkay"
targetcontrolid="lnkDummy"
popupcontrolid="Panel1"
BehaviorID="mpe"
backgroundcssclass="ModalPopupBG">
</ajaxToolkit:modalpopupextender>
<asp:panel id="Panel1" style="display: none" runat="server" CssClass="modalPopup">
<div class="PopupHeader" id="PopupHeader">
<asp:Literal runat="server" Id="TheHeader"></asp:Literal>
</div>
<div class="PopupBody">
<input id="btnOkay" type="button" value="OK" />
</div>
</asp:panel>
我猜想这与回发等有关,但是我不确定如何配置它,以便手风琴可以按我应该做的方式工作。