我正在使用ASP.NET(Visual C#)在SharePoint可視Web部件中創建自定義視圖,並具有CheckBoxList和一個按鈕。CheckBoxList被清除按鈕單擊
標記的列表&按鈕:
<td>
<asp:checkboxlist ID="cblYearLst" runat="server" EnableViewState="true" />
</td>
<td>
<asp:Button ID="btnRefineSearch" Text="Refine Search" runat="server" />
</td>
我將項目添加到CheckBoxList的上預渲染:
if (!IsPostBack)
{
if (LstYears != null)
{
for (int i = 0; i < LstYears.Count(); i++)
{
cblYearLst.Items.Add(new ListItem(LstYears[i], LstYears[i]));
}
}
}
我呼籲按鈕的事件處理程序上的Page_Load:
btnRefineSearch.Click += new EventHandler(this.btnRefineSearch_Click);
按鈕之後,所有CheckBox列表項都不會保持選中狀態點擊。我可以檢索選定的值,但不會顯示爲選定的值。當我在預渲染事件中爲按鈕添加Click事件處理程序時,數據會正確顯示,但是我的Click事件不能再檢索選定的值。
關於什麼可能會導致此行爲的任何想法?
我認爲你在週期中太晚加入物品。將它們添加到Init上的PreInit上:http://stackoverflow.com/questions/2724771/checkboxlist-not-setting-selected-with-viewstate-disabled – jmaglio 2012-03-06 14:30:33
@jfmags我已經嘗試了您提供的建議,但列表不再顯示。 – anpatel 2012-03-06 14:34:08
你在哪裏設置LstYears? – jmaglio 2012-03-06 14:42:44