dropdownlist3级联动菜单数据存储问题

gnl8 2005-02-02 09:38:05
我用的是下面的方法做的3级联动
TreeDropDownList.aspx
<%@ Page language="c#" Codebehind="TreeDropDownList.aspx.cs" AutoEventWireup="false" Inherits="news.TreeDropDownList" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>TreeDropDownList</title>
<meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<script language="javascript">

var Wantcount;
var Groupcount;

Groupcount=0;

Group = new Array();
<asp:Literal id="Want" runat="server"></asp:Literal>

function changelocation1(locationid)
{
document.submit.DirectionList1.length = 0;
document.submit.WantList1.length = 0;
var locationid=locationid;
var i;
var flag;
var j;
for (i=0;i<Groupcount; i++)
{
if (Group[i][0] == locationid)
{
flag = true;
for (j =0;j<document.submit.DirectionList1.length;j++)
if (document.submit.DirectionList1[j].value == Group[i][1])
{
flag = false;
break;
}
if (flag)
document.submit.DirectionList1.options[document.submit.DirectionList1.length]
= new Option(Group[i][1], Group[i][1]);
}
}
}


function changelocation11(locationid, direction)
{
document.submit.WantList1.length = 0;
var locationid=locationid;
var i;
var flag;
var j;
for (i=0;i<Groupcount;i++)
{
if (Group[i][0] == locationid && Group[i][1] == direction)
{

flag = true;
for (j=0;j<document.submit.WantList1.length;j++)
if (document.submit.WantList1[j].value == Group[i][2])
{
flag = false;
break;
}
if (flag)
document.submit.WantList1.options[document.submit.WantList1.length]
= new Option(Group[i][2], Group[i][2]);
}
}
}
//function changelocation11(direction1)
//{
//document.submit.reason.value=direction1;
//}
</script>
</HEAD>
<BODY ms_positioning="GridLayout">
<form id="submit" method="post" runat="server">
<TABLE style="Z-INDEX: 101; LEFT: 184px; POSITION: absolute; TOP: 144px">
<TR>
<TD style="WIDTH: 115px; HEIGHT: 17px" align="center">求职意向:</TD>
<TD style="HEIGHT: 17px"><asp:dropdownlist id="SourceList1" runat="server" Width="100px" onchange="changelocation1(document.submit.SourceList1.options[document.submit.SourceList1.selectedIndex].value);changelocation11(document.submit.SourceList1.options[document.submit.SourceList1.selectedIndex].value,document.submit.DirectionList1.options[document.submit.DirectionList1.selectedIndex].value)"
DataValueField="v_source" DataTextField="v_source"></asp:dropdownlist><asp:dropdownlist id="DirectionList1" runat="server" Width="100px" onchange="changelocation11(document.submit.SourceList1.options[document.submit.SourceList1.selectedIndex].value,document.submit.DirectionList1.options[document.submit.DirectionList1.selectedIndex].value)"
DataValueField="v_GroupName"></asp:dropdownlist><asp:dropdownlist id="WantList1" runat="server" Width="100px" DataValueField="v_title"></asp:dropdownlist></TD>
</TR>
<tr>
<td><asp:Label Runat="server" ID="reason" Width="40"></asp:Label></td>
<td><asp:Label Runat="server" ID="jiafen" Width="40"></asp:Label></td>
</tr>
</TABLE>

</form>
<script language="javascript">
changelocation1(document.submit.SourceList1.options[document.submit.SourceList1.selectedIndex].value);
changelocation11(document.submit.SourceList1.options[document.submit.SourceList1.selectedIndex].value,document.submit.DirectionList1.options[document.submit.DirectionList1.selectedIndex].value)
// changelocation12(document.submit.WantList1.options[document.submit.WantList1.selectedIndex].value)
</script>
</BODY>
</HTML>

TreeDropDownList.aspx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace news
{
/// <summary>
/// TreeDropDownList 的摘要说明。
/// </summary>
public class TreeDropDownList : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Literal Want;
protected System.Web.UI.WebControls.DropDownList SourceList1;
protected System.Web.UI.WebControls.DropDownList DirectionList1;
protected System.Web.UI.WebControls.DropDownList WantList1;
protected System.Web.UI.WebControls.Label reason;
protected System.Web.UI.WebControls.Label jiafen;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Literal Group;

private void Page_Load(object sender, System.EventArgs e)
{
//if (!IsPostBack)
//{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("a.xml"));
for(int i = 0;i <ds.Tables[0].Rows.Count ;i++)
{
DataRow dr = ds.Tables[0].Rows[i];
Want.Text += String.Format("Group[Groupcount++] = new Array(\"{0}\",\"{1}\",\"{2}\");\n", dr["v_Source"],dr["v_GroupName"].ToString(), dr["v_title"].ToString());
if (SourceList1.Items.FindByText(dr["v_Source"].ToString()) == null)
{
SourceList1.Items.Add(dr["v_Source"].ToString());
}
}
//}
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion


}
}
...全文
152 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
programmeraaron 2005-02-05
  • 打赏
  • 举报
回复
和我抢分
seesea125 2005-02-03
  • 打赏
  • 举报
回复
赋值多的话用|等特别字符分隔,然后用spilt拆分就行
seesea125 2005-02-03
  • 打赏
  • 举报
回复
举个例子:一个select,一个隐藏控件
<select onchange="changeselect1(this.value)" name="s1">
<OPTION selected value="请选择">==请选择==</OPTION>
<OPTION selected value="aa">aa</OPTION>
</select>
<INPUT id="addvalue" type="hidden" runat="server">
触发的changeselect1(this.value)这个函数里
function changeselect1(locationid)
{
//先给第二个select菜单s2赋值
然后
document.all.addvalue.value="";//清空以前的旧值
document.all.addvalue.value=document.all.s2.optionss[this.selectedIndex].value //赋值给隐藏控件
}
seesea125 2005-02-03
  • 打赏
  • 举报
回复
程序太长了,就不看了,如果你的菜单是用javascript填的值,那么需要一个隐藏控件
<input type=hidden id='a' name='a' runat="server">这样的控件
在给你菜单赋值后,选中值时触发javascript函数,在函数里把值赋给这个hidden控件,这样才能接收的
programmeraaron 2005-02-03
  • 打赏
  • 举报
回复
就是按下 提交 按钮,先在客户端执行自定义函数,在这个函数里把当前选择的项编码,然后保存到hidden里,如:item1;item2;item3

然后document.forms[0].submit();
在server端,用Split函数把字符串分解到string[]里,然后就知道选择的是什么了
gnl8 2005-02-02
  • 打赏
  • 举报
回复
up
gnl8 2005-02-02
  • 打赏
  • 举报
回复
<input type="hidden" value="条件">这个条件要怎么写呀???
心情解码 2005-02-02
  • 打赏
  • 举报
回复
up




--
gnl8 2005-02-02
  • 打赏
  • 举报
回复
能不能给个例子看一下,这样说我还是有点不明白呀。谢谢
programmeraaron 2005-02-02
  • 打赏
  • 举报
回复
提交前先把选中的 按照文本方式保存在hidden里,提交后在分解字符串,然后再添加
gnl8 2005-02-02
  • 打赏
  • 举报
回复
现在遇到问题,我做的是会员注册程序,都选择好行业后,提交,存入数据库的只有第一个dropdownlist,后2个dropdownlist不能存入数据库,我用的存储方法是:
string sql = "insert into [ce_user] (guojia,shengfen,chengshi)" +
"values ('" + guojia.SelectedValue.ToString() + "','" + shengfen.SelectedValue.ToString() + "','" + chengshi.SelectedValue.ToString() + "')";
mycommand = new SqlCommand(sql,obj.sqlconn);
gnl8 2005-02-02
  • 打赏
  • 举报
回复
a.xml
<?xml version="1.0" encoding="GB2312" ?>
<DataSource>
<Data>
<v_Source>计算机类</v_Source>
<v_GroupName>软件</v_GroupName>
<v_title>程序员</v_title>
</Data>
<Data>
<v_Source>计算机类</v_Source>
<v_GroupName>软件</v_GroupName>
<v_title>系统分析员</v_title>
</Data>
<Data>
<v_Source>计算机类</v_Source>
<v_GroupName>软件</v_GroupName>
<v_title>项目经理</v_title>
</Data>
<Data>
<v_Source>计算机类</v_Source>
<v_GroupName>硬件</v_GroupName>
<v_title>网络工程师</v_title>
</Data>
<Data>
<v_Source>计算机类</v_Source>
<v_GroupName>硬件</v_GroupName>
<v_title>计算机维护</v_title>
</Data>
<Data>
<v_Source>计算机类</v_Source>
<v_GroupName>数据库</v_GroupName>
<v_title>数据库开发</v_title>
</Data>
<Data>
<v_Source>计算机类</v_Source>
<v_GroupName>数据库</v_GroupName>
<v_title>数据库管理</v_title>
</Data>
<Data>
<v_Source>行政/管理类</v_Source>
<v_GroupName>行政</v_GroupName>
<v_title>文秘</v_title>
</Data>
<Data>
<v_Source>行政/管理类</v_Source>
<v_GroupName>行政</v_GroupName>
<v_title>助理</v_title>
</Data>
<Data>
<v_Source>行政/管理类</v_Source>
<v_GroupName>管理</v_GroupName>
<v_title>总经理</v_title>
</Data>
<Data>
<v_Source>行政/管理类</v_Source>
<v_GroupName>管理</v_GroupName>
<v_title>部门经理</v_title>
</Data>
<Data>
<v_Source>行政/管理类</v_Source>
<v_GroupName>管理</v_GroupName>
<v_title>总监</v_title>
</Data>
</DataSource>

62,266

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧