public static ListItem[] GetTSpecialTree() { List<ListItem> Result = new List<ListItem>(); Result.Add(new ListItem("---请选择---", "-1")); usp_TSpecial_ByAll usp = new usp_TSpecial_ByAll(); DataTable dt = usp.ExecDataTable(); DataRow[] dr = dt.Select("IsEnabled = 0"); for (int i = 0; i < dr.Length; i++) { string Separator = "├—"; string Text = dr[i]["Name"].ToString().Trim(); string Value = dr[i]["SpecialID"].ToString().Trim(); Result.Add(new ListItem(Text, Value)); BindNode(ref Result, Value, dt, Separator); } return Result.ToArray(); } private static void BindNode(ref List<ListItem> listItemCollection, string parentId, DataTable dt, string separator) { DataRow[] dr = dt.Select("IsEnabled=" + parentId); for (int i = 0; i < dr.Length; i++) { if (i + 1 == dr.Length) { separator = separator.Replace("├—", "└—"); } string Text = separator + dr[i]["Name"].ToString().Trim(); string Value = dr[i]["SpecialID"].ToString().Trim(); listItemCollection.Add(new ListItem(Text, Value)); if (i + 1 == dr.Length) { separator = separator.Replace("└—", "├—"); } BindNode(ref listItemCollection, Value, dt, System.Web.HttpUtility.HtmlDecode("┆ ") + separator); //"││┃┆┊┋"; } } 你改改就能用了,你的DropDownList1.Items.AddRange(NewsRule.GetTSpecialTree())就可以载入了
<asp:SqlDataSource ID="SqlDataSource6" runat="server" ConnectionString="<%$ ConnectionStrings:MySqlProviderConnection %>" SelectCommand="SELECT 0 AS WareHouseID,'所有仓库' AS Description, 'NULL->0' AS Label Union SELECT [WareHouseID], REPLICATE ('|- ', [Level]) + [Description] AS Description, Label FROM dbo.GetWareHouseTreeInfo() order by [Label]"></asp:SqlDataSource> <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource6" DataTextField="Description" DataValueField="WareHouseID"> </asp:DropDownList>
public static ListItem[] GetTSpecialTree() { List <ListItem> Result = new List <ListItem>(); Result.Add(new ListItem("---请选择---", "-1")); usp_TSpecial_ByAll usp = new usp_TSpecial_ByAll(); DataTable dt = usp.ExecDataTable(); DataRow[] dr = dt.Select("IsEnabled = 0"); for (int i = 0; i < dr.Length; i++) { string Separator = "├—"; string Text = dr[i]["Name"].ToString().Trim(); string Value = dr[i]["SpecialID"].ToString().Trim(); Result.Add(new ListItem(Text, Value)); BindNode(ref Result, Value, dt, Separator); } return Result.ToArray(); } private static void BindNode(ref List <ListItem> listItemCollection, string parentId, DataTable dt, string separator) { DataRow[] dr = dt.Select("IsEnabled=" + parentId); for (int i = 0; i < dr.Length; i++) { if (i + 1 == dr.Length) { separator = separator.Replace("├—", "└—"); } string Text = separator + dr[i]["Name"].ToString().Trim(); string Value = dr[i]["SpecialID"].ToString().Trim(); listItemCollection.Add(new ListItem(Text, Value)); if (i + 1 == dr.Length) { separator = separator.Replace("└—", "├—"); } BindNode(ref listItemCollection, Value, dt, System.Web.HttpUtility.HtmlDecode("┆ ") + separator); //"││┃┆┊┋"; } }
难道这一小块用asp 最后在HTML表单中加个 runat="server" ? 如果不想用ASP语言,就想用.net
实现起来是不是难度很大?
{
List<ListItem> Result = new List<ListItem>();
Result.Add(new ListItem("---请选择---", "-1")); usp_TSpecial_ByAll usp = new usp_TSpecial_ByAll();
DataTable dt = usp.ExecDataTable();
DataRow[] dr = dt.Select("IsEnabled = 0"); for (int i = 0; i < dr.Length; i++)
{
string Separator = "├—";
string Text = dr[i]["Name"].ToString().Trim();
string Value = dr[i]["SpecialID"].ToString().Trim();
Result.Add(new ListItem(Text, Value));
BindNode(ref Result, Value, dt, Separator);
}
return Result.ToArray();
}
private static void BindNode(ref List<ListItem> listItemCollection, string parentId, DataTable dt, string separator)
{
DataRow[] dr = dt.Select("IsEnabled=" + parentId);
for (int i = 0; i < dr.Length; i++)
{
if (i + 1 == dr.Length)
{
separator = separator.Replace("├—", "└—");
}
string Text = separator + dr[i]["Name"].ToString().Trim();
string Value = dr[i]["SpecialID"].ToString().Trim();
listItemCollection.Add(new ListItem(Text, Value));
if (i + 1 == dr.Length)
{
separator = separator.Replace("└—", "├—");
}
BindNode(ref listItemCollection, Value, dt, System.Web.HttpUtility.HtmlDecode("┆ ") + separator);
//"││┃┆┊┋";
}
}
你改改就能用了,你的DropDownList1.Items.AddRange(NewsRule.GetTSpecialTree())就可以载入了
SelectCommand="SELECT 0 AS WareHouseID,'所有仓库' AS Description, 'NULL->0' AS Label Union SELECT [WareHouseID], REPLICATE ('|- ', [Level]) + [Description] AS Description, Label FROM dbo.GetWareHouseTreeInfo() order by [Label]"></asp:SqlDataSource>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource6"
DataTextField="Description" DataValueField="WareHouseID">
</asp:DropDownList>
{
List <ListItem> Result = new List <ListItem>();
Result.Add(new ListItem("---请选择---", "-1")); usp_TSpecial_ByAll usp = new usp_TSpecial_ByAll();
DataTable dt = usp.ExecDataTable();
DataRow[] dr = dt.Select("IsEnabled = 0"); for (int i = 0; i < dr.Length; i++)
{
string Separator = "├—";
string Text = dr[i]["Name"].ToString().Trim();
string Value = dr[i]["SpecialID"].ToString().Trim();
Result.Add(new ListItem(Text, Value));
BindNode(ref Result, Value, dt, Separator);
}
return Result.ToArray();
}
private static void BindNode(ref List <ListItem> listItemCollection, string parentId, DataTable dt, string separator)
{
DataRow[] dr = dt.Select("IsEnabled=" + parentId);
for (int i = 0; i < dr.Length; i++)
{
if (i + 1 == dr.Length)
{
separator = separator.Replace("├—", "└—");
}
string Text = separator + dr[i]["Name"].ToString().Trim();
string Value = dr[i]["SpecialID"].ToString().Trim();
listItemCollection.Add(new ListItem(Text, Value));
if (i + 1 == dr.Length)
{
separator = separator.Replace("└—", "├—");
}
BindNode(ref listItemCollection, Value, dt, System.Web.HttpUtility.HtmlDecode("┆ ") + separator);
//"││┃┆┊┋";
}
}