我希望显示类似于Ebay用于类别选择的动态列表框
http://cgi5.ebay.com/ws/eBayISAPI.dll?NewListing&sid=&cpg=134&aid=6(您必须登录以查看类别的工作方式)
以下是屏幕截图:Ebay Screenshot http://www.aquariumbids.com/Images/ebayCat.JPG
任何解释此代码或代码示例的文档的链接都将不胜感激。
到目前为止,这是我的代码:
protected void Page_Load(object sender, EventArgs e)
{
ListBox Temp = CreateListBox();
UpdatePanel1.ContentTemplateContainer.Controls.Add(Temp);
PlaceHolder1.Controls.Add(Temp);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
protected ListBox CreateListBox()
{
ListBox lb = new ListBox();
DataTable Categories = Globals.g_DatabaseHandler.GetRecords(StoredProcedures.GetMainCategories, new Dictionary<string, string>() { });
foreach (DataRow row in Categories.Rows)
{
lb.Items.Add(new ListItem(row[1].ToString(), row[0].ToString()));
}
lb.AutoPostBack = true;
lb.CssClass = "panel";
lb.SelectedIndexChanged += new EventHandler(ListBox_SelectionChanged);
return lb;
}
/// <summary>
///
/// </summary>
/// <param name="CatId"></param>
/// <returns></returns>
protected ListBox CreateListBox(string CatId)
{
ListBox lb = new ListBox();
Dictionary<string, string> Params = new Dictionary<string, string>();
Params.Add("parentID", CatId);
DataTable Categories = Globals.g_DatabaseHandler.GetRecords(StoredProcedures.GetChildCategories, Params);
if (Categories.Rows.Count > 0)
{
foreach (DataRow row in Categories.Rows)
{
lb.Items.Add(new ListItem(row[1].ToString(), row[0].ToString()));
}
lb.AutoPostBack = true;
lb.CssClass = "panel";
lb.SelectedIndexChanged += new EventHandler(ListBox_SelectionChanged);
}
return lb;
}
protected void ListBox_SelectionChanged(object sender, EventArgs arg)
{
string ID = ((ListBox)sender).SelectedValue;
ListBox Temp = CreateListBox(ID);
UpdatePanel1.ContentTemplateContainer.Controls.Add(Temp);
PlaceHolder1.Controls.Add(Temp);
}
这是标记
<div id="wrapper">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
</div>