在DropDownList1中,绑定select distinct JH from ah202_1,然后在DropDownList1中选择一个JH字段;之后在DropDownList2中绑定select TC from ah202_1 where JH='"+DropDownList1.SelectedItem.Text+"'; 请问高手怎么解决?要注意的是,存在一个刷新问题,有代码的请给代码,没代码的给个思路!在线等待急呀急
解决方案 »
- 我的项目代码被删掉了 是剩下bin目录下的.dll 和页面文件了急
- 终于扛不住了,有招聘的公司没。
- 在asp.net的c#中读入有规律的字段内容,比如字段a1,a2……a100中,读取第a75,能不能带参数的读取字段内容
- 问个问题啦!
- 上传文件的类型问题,很简单的
- 朋友.帮我一个忙..我想在这个表格用javascript在<table><tr>中间加一段html代码.如何弄??
- .aspx文件运行出现未能生成.dll文件的问题?请能解决?
- dreamweaver中的asp.net,急~~~~~~~~~~~~~~~~
- 为什么我的DataGrid的在发生OnItemCommand事件时,老是执行两次呀?
- .net新手的问题
- 有点难度(如何给控件(TextBox)数组添加一个事件)
- News:下一代CSDN社区将有货币和道具,救济金还新增钻石级别...详情请看
在DropDownList1的selectedindexchange事件中写第二个DropDownList绑定
{
if (!IsPostBack)
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("DataSource.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());
}
}
}
}<%@ Page language="c#" Codebehind="TreeDropDownList.aspx.cs" AutoEventWireup="false" Inherits="TowDropDownList.TowDropDownList" %>
<!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]);
}
}
} </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="middle">求职意向:</TD>
<TD style="HEIGHT: 17px"><asp:dropdownlist id="SourceList1" runat="server" DataTextField="v_source" DataValueField="v_source" 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)" Width="100px"></asp:dropdownlist><asp:dropdownlist id="DirectionList1" runat="server" DataValueField="v_GroupName" onchange="changelocation11(document.submit.SourceList1.options[document.submit.SourceList1.selectedIndex].value,document.submit.DirectionList1.options[document.submit.DirectionList1.selectedIndex].value)" Width="100px"></asp:dropdownlist><asp:dropdownlist id="WantList1" runat="server" DataValueField="v_title" Width="100px"></asp:dropdownlist></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)
</script>
</BODY>
</HTML><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>
楼主的意思究竟是可不可以刷新呢?
如果可以,楼上的已经说全了
Dropdownlist1.autopostback属性设为true
private void DropDownList1_selectedindexchange(...)
{事件中写第二个DropDownList绑定}如果不可以刷新就比较麻烦,可以把第二下拉框的数据全部取出来变成一个脚本里的数组,用脚本进行查询;或者用脚本调用webservice的方法去做数据库查询
dropdownlist2.SelectedIndex=i
--欧阳如枫[^_^(笑一个)]
〔努力拼搏〕〔拼搏奋斗〕〔奋斗进取〕〔进取努力〕
愿你和我一样快乐。
对你的想法比较感兴趣,能具体的谈谈吗?现在的问题是我选第一个DropDownList里的数据,就刷新了页面,又回到原始状态,请赐教!
这样,他就不会回到原始状态了
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using Coremis.AllPages.dboperation;
using HFSecurityLib;
namespace Coremis.AllPages.operajing
{
/// <summary>
/// ImageOper 的摘要说明。
/// </summary>
public class ImageOper : System.Web.UI.Page
{
private DbConnector m_DbConnector=null;
private string Global_GroupName="";
private string m_strCurrJH="";
private string m_strAllJH="";
protected System.Web.UI.WebControls.DropDownList DropdownlisttongCi;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Button BtBrower;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.DropDownList DropDownListjingName;
private void Page_Load(object sender, System.EventArgs e)
{ m_DbConnector=DbConnector.CreateInstance();
m_DbConnector.ConnectToOracle(Session); if(!Page.IsPostBack)
{
if(Request["alljh"]==null || Request["currjh"]==null)
{
Response.Write("参数传递错误!");
Response.End();
}
try
{
HFSecurityLib.WebUserClass Global_UserObject=(WebUserClass)Session["WebUserObject"];
string Global_UserName=Global_UserObject.Account;//Session("LoginUserName");
string Global_UserPass=Global_UserObject.Password;//Session("LoginUserPass");
if (Global_UserObject==null) Response.Redirect("../ErrPage.asp?ErrorMsg=用户已经超时,请重新登陆");
if (Global_UserObject.Status<=0)
{
Response.Redirect("../ErrPage.asp?ErrorMsg=您的连结被管理员切断了");
}
if(Global_UserObject.Group!=null)
{
Global_GroupName=Global_UserObject.Group.Name;
}
}
catch(Exception err)
{
Response.Redirect("../ErrPage.asp?ErrorMsg=用户已经超时,请重新登陆");
} m_strAllJH=Request["alljh"].ToString();
m_strCurrJH=Request["currjh"].ToString();
DropDownListjingName.AutoPostBack=true;
CreateToolBarjingName();
}
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DropDownListjingName.SelectedIndexChanged += new System.EventHandler(this.DropDownListjingName_SelectedIndexChanged);
this.BtBrower.Click += new System.EventHandler(this.BtBrower_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void CreateToolBarjingName()
{
DataSet ds=new DataSet();
string[] strTempArray=m_strAllJH.Split('|');
foreach(string strTemp in strTempArray)
{
OleDbConnection cn=m_DbConnector.GetConnection();
string strSQL="select distinct JH from ah202_1 where JH='"+strTemp+"'";
OleDbDataAdapter myAdapter=new OleDbDataAdapter(strSQL,cn);
myAdapter.Fill(ds);
}
DropDownListjingName.DataSource=ds.Tables[0].DefaultView;
DropDownListjingName.DataTextField="JH";
DropDownListjingName.DataValueField="JH";
DropDownListjingName.DataBind();
}
private void DropDownListjingName_SelectedIndexChanged(object sender, System.EventArgs e)
{
OleDbConnection cn=m_DbConnector.GetConnection();
DataSet ds=new DataSet();
OleDbDataAdapter adapter=new OleDbDataAdapter("select distinct TC from AH202_1 where jh='" +DropDownListjingName.SelectedValue.ToString()+ "'",cn);
adapter.Fill(ds,"adapter");
DropdownlisttongCi.DataSource=ds.Tables["adapter"].DefaultView;
DropdownlisttongCi.DataTextField="TC";
DropdownlisttongCi.DataValueField="TC";
DropdownlisttongCi.DataBind();
} private void BtBrower_Click(object sender, System.EventArgs e)
{
DropdownlisttongCi.AutoPostBack=true;
string strsd="";
string strSql="select sd1 from AH202_1 where tc='"+DropdownlisttongCi.SelectedItem.Text+"'";
DataSet ds=m_DbConnector.GetDataSet(strSql);
if(ds.Tables[0].Rows.Count>=1)
{
for(int i=0;i<ds.Tables[0].Rows.Count-1;i++)
{
strsd=ds.Tables[0].Rows[0][0].ToString();
break;
}
}
TextBox1.Text=DropDownListjingName.SelectedItem.Text.ToString();
TextBox2.Text=strsd;
}
}
}
private void drop_dq_SelectedIndexChanged(object sender, System.EventArgs e)
{
this.drop_sx.Items.Clear();
DataSet dst=new DataSet();
gl.viewnum(dst,this.drop_dq.SelectedItem.Text);
gl.viewsx(dst,dst.Tables[0].Rows[0]["id"].ToString());
for(int i=0;i<dst.Tables[1].Rows.Count;i++)
{
this.drop_sx.Items.Add(dst.Tables[1].Rows[i]["regionname"].ToString());
}
}
我都懒的改了,先要把第一个的autopostback设置为TRUE,不然不会立即触发事件
然后再在它的SelectedIndexChanged事件里面写代码,呵呵
dropdownlist.autopost=true
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
CreateDropDownList1();
}private void CreateDropDownList1()
{
string[] strTempArray=m_strAllJH.Split('|');
ArrayList arr=new ArrayList();
foreach(string strTemp in strTempArray)
{
arr.Add(strTemp);
}
DropDownList1.DataSource=arr;
DropDownList1.DataBind();
}
请各位再次帮帮忙!马上给分。。
<globalization
requestEncoding="gb2312"
responseEncoding="gb2312"
/>
因为我在传值过程中使用了中文,所以,当把中文绑定到DropDownList中时,就会出现选择时,刷新到原始状态。并不是简单的数据绑定。