[dd.aspx.vb]
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Call init_porvince_DropDownlist()
End If
End SubPrivate Sub init_per_DropDownList()
Dim SQLConn As SqlConnection
Dim SQLConnstr As String
SQLConnstr = ConfigurationSettings.AppSettings("SQLConnstr")
SQLConn = New SqlConnection(SQLConnstr)
SQLConn.Open()
Dim cmd As New SqlCommand
cmd.Connection = SQLConn
Dim SQLstr As String = "select id,title from suminfo_Profession_bigclass"
cmd.CommandText = SQLstr
Dim sql_adpt As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim per_big_ds As DataTable = New DataTable
sql_adpt.Fill(per_big_ds)
perb_DropDownList.DataSource = per_big_ds
perb_DropDownList.DataTextField = "title"
perb_DropDownList.DataValueField = "id"
perb_DropDownList.DataBind()
Dim big_legth As Integer = per_big_ds.Rows.Count()
Dim sbscript As New System.Text.StringBuilder
sbscript.Append("<script><!--")
sbscript.Append(Environment.NewLine & "var group=new Array(" & big_legth & ");for(i=0;i<" & big_legth & ";i++){group[i]=new Array()}" & Environment.NewLine)
Dim i As Integer
Dim j As Integer
Dim tempclass As DataTable
Dim classlegth As Integer
For i = 0 To big_legth - 1
SQLstr = "select id,title from suminfo_Profession_smallclass where bigclass_id=" & CInt(per_big_ds.Rows(i)(0))
cmd.CommandText = SQLstr
sql_adpt = New SqlDataAdapter(cmd)
tempclass = New DataTable
sql_adpt.Fill(tempclass)
classlegth = tempclass.Rows.Count()
For j = 0 To classlegth - 1
sbscript.Append("group[" & i & "][" & j & "]=new Option(""" & tempclass.Rows(j)(1) & """,""" & tempclass.Rows(j)(0) & """);" & Environment.NewLine)
Next
Next
sbscript.Append(Environment.NewLine & "function redirect(x){" & Environment.NewLine & "for(m=Form1.pers_DropDownList.options.length-1;m>0;m--){Form1.pers_DropDownList.options[m]=null}")
sbscript.Append(Environment.NewLine & "for (i=0;i<group[x].length;i++){" & Environment.NewLine & "Form1.pers_DropDownList.options[i]=new Option(group[x][i].text,group[x][i].value)}")
sbscript.Append(Environment.NewLine & "Form1.pers_DropDownList.options[0].selected=true;Form1.classid.value=Form1.pers_DropDownList.options[0].value;}")
sbscript.Append(Environment.NewLine & "function choose(x){Form1.classid.value=Form1.pers_DropDownList.options[x].value;}")
sbscript.Append(Environment.NewLine & "--></script>")
Dim strscript As String = sbscript.ToString()
If (Not IsClientScriptBlockRegistered("clientScript")) Then
RegisterClientScriptBlock("clientScript", strscript)
End If
SQLstr = "SELECT id,title FROM suminfo_Profession_smallclass WHERE id=" & CInt(per_big_ds.Rows(0)(0))
cmd.CommandText = SQLstr
sql_adpt = New SqlDataAdapter(cmd)
Dim per_small_ds As DataTable = New DataTable
sql_adpt.Fill(per_small_ds)
pers_DropDownList.DataSource = per_small_ds
pers_DropDownList.DataValueField = "id"
pers_DropDownList.DataTextField = "title"
If Not IsPostBack Then pers_DropDownList.DataBind()
sql_adpt.Dispose()
cmd.Dispose()
cmd = Nothing
sql_adpt.Dispose()
sql_adpt = Nothing
per_big_ds.Dispose()
per_big_ds = Nothing
SQLConn.Close()
End Sub[dd.aspx]
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="professions.aspx.vb" Inherits="sumdata_datacenter.professions"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>professions</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<style>TD { FONT-SIZE: 9pt }
</style>
<script language="javascript">
function XmlPost3(obj,fullname,sType)
{
var svalue=obj.value;
var mytopname="";
if(sType == "1")
{
mytopname="请选择名称";
}
else
{
mytopname="请选择子类名称";
}
var fullObj=document.all(fullname);
var webFileUrl = "?sortid=" + svalue + "&sType=" + sType;
var result = "";
var xmlHttp = new ActiveXobject("MSXML2.XMLHTTP");
xmlHttp.open("POST" ,webFileUrl, false);
xmlHttp.send("");
result = xmlHttp.responseText;
if(result != "" && svalue != "")
{
fullObj.length=0;
fullObj.options.add(new Option(mytopname,""));
var piArray = result.split(",");
for(var i=0;i<piArray.length;i++)
{
var ary1 = piArray[i].toString().split("|");
fullObj.options.add(new Option(ary1[1].toString(),ary1[0],toString()));
}
}
else
{
fullObj.length = 0;
fullObj.options.add(new Option(mytopname,""));
}
if(sType == "1")
{
document.all("bc_DropDownList").length = 0;
document.all("sc_DropDownList").options.add(new Option(mytopname,""));
}
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<INPUT id="classid" type="text" runat="server" NAME="classid" style="display:none;">
<table cellpadding="0" cellspacing="0" width="96%" align="center" border="0">
<tr>
<td style="HEIGHT: 17px">
行业分类:<asp:DropDownList id="bc_DropDownList" runat="server" onchange="redirect(this.options.selectedIndex)"></asp:DropDownList>
行业子类:<asp:DropDownList id="sc_DropDownList" runat="server" onchange="choose(this.options.selectedIndex)"></asp:DropDownList>
<asp:Button id="del_bc" runat="server" Text="删除分类" Width="73"></asp:Button>
<asp:Button id="del_sc" runat="server" Text="删除子类" Width="73"></asp:Button>
</td>
</tr>
<tr>
<td height="16" style="HEIGHT: 16px"></td>
</tr>
<tr>
<td>
添加分类:<asp:TextBox id="bc_add_textbox" runat="server"></asp:TextBox>
<asp:Button id="bc_submit" runat="server" Text="添加分类" Width="73"></asp:Button>
</td>
</tr>
<tr>
<td>
添加子类:<asp:DropDownList id="bc_add_DropDownList" runat="server"></asp:DropDownList>
<asp:TextBox id="sc_add_textbox" runat="server"></asp:TextBox>
<asp:Button id="Button4" runat="server" Text="添加子类" Width="73"></asp:Button>
</td>
</tr>
</table>
</FONT>
</form>
</body>
</HTML>以上代码是从网上找来的,开始的时候运行正常,可是把 id为1 的记录删除后总用sc_DropDownList.SelectedValue总是提不出第二个dropdownlist的值,请各位大侠指点一下,谢谢~~~~~
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Call init_porvince_DropDownlist()
End If
End SubPrivate Sub init_per_DropDownList()
Dim SQLConn As SqlConnection
Dim SQLConnstr As String
SQLConnstr = ConfigurationSettings.AppSettings("SQLConnstr")
SQLConn = New SqlConnection(SQLConnstr)
SQLConn.Open()
Dim cmd As New SqlCommand
cmd.Connection = SQLConn
Dim SQLstr As String = "select id,title from suminfo_Profession_bigclass"
cmd.CommandText = SQLstr
Dim sql_adpt As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim per_big_ds As DataTable = New DataTable
sql_adpt.Fill(per_big_ds)
perb_DropDownList.DataSource = per_big_ds
perb_DropDownList.DataTextField = "title"
perb_DropDownList.DataValueField = "id"
perb_DropDownList.DataBind()
Dim big_legth As Integer = per_big_ds.Rows.Count()
Dim sbscript As New System.Text.StringBuilder
sbscript.Append("<script><!--")
sbscript.Append(Environment.NewLine & "var group=new Array(" & big_legth & ");for(i=0;i<" & big_legth & ";i++){group[i]=new Array()}" & Environment.NewLine)
Dim i As Integer
Dim j As Integer
Dim tempclass As DataTable
Dim classlegth As Integer
For i = 0 To big_legth - 1
SQLstr = "select id,title from suminfo_Profession_smallclass where bigclass_id=" & CInt(per_big_ds.Rows(i)(0))
cmd.CommandText = SQLstr
sql_adpt = New SqlDataAdapter(cmd)
tempclass = New DataTable
sql_adpt.Fill(tempclass)
classlegth = tempclass.Rows.Count()
For j = 0 To classlegth - 1
sbscript.Append("group[" & i & "][" & j & "]=new Option(""" & tempclass.Rows(j)(1) & """,""" & tempclass.Rows(j)(0) & """);" & Environment.NewLine)
Next
Next
sbscript.Append(Environment.NewLine & "function redirect(x){" & Environment.NewLine & "for(m=Form1.pers_DropDownList.options.length-1;m>0;m--){Form1.pers_DropDownList.options[m]=null}")
sbscript.Append(Environment.NewLine & "for (i=0;i<group[x].length;i++){" & Environment.NewLine & "Form1.pers_DropDownList.options[i]=new Option(group[x][i].text,group[x][i].value)}")
sbscript.Append(Environment.NewLine & "Form1.pers_DropDownList.options[0].selected=true;Form1.classid.value=Form1.pers_DropDownList.options[0].value;}")
sbscript.Append(Environment.NewLine & "function choose(x){Form1.classid.value=Form1.pers_DropDownList.options[x].value;}")
sbscript.Append(Environment.NewLine & "--></script>")
Dim strscript As String = sbscript.ToString()
If (Not IsClientScriptBlockRegistered("clientScript")) Then
RegisterClientScriptBlock("clientScript", strscript)
End If
SQLstr = "SELECT id,title FROM suminfo_Profession_smallclass WHERE id=" & CInt(per_big_ds.Rows(0)(0))
cmd.CommandText = SQLstr
sql_adpt = New SqlDataAdapter(cmd)
Dim per_small_ds As DataTable = New DataTable
sql_adpt.Fill(per_small_ds)
pers_DropDownList.DataSource = per_small_ds
pers_DropDownList.DataValueField = "id"
pers_DropDownList.DataTextField = "title"
If Not IsPostBack Then pers_DropDownList.DataBind()
sql_adpt.Dispose()
cmd.Dispose()
cmd = Nothing
sql_adpt.Dispose()
sql_adpt = Nothing
per_big_ds.Dispose()
per_big_ds = Nothing
SQLConn.Close()
End Sub[dd.aspx]
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="professions.aspx.vb" Inherits="sumdata_datacenter.professions"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>professions</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<style>TD { FONT-SIZE: 9pt }
</style>
<script language="javascript">
function XmlPost3(obj,fullname,sType)
{
var svalue=obj.value;
var mytopname="";
if(sType == "1")
{
mytopname="请选择名称";
}
else
{
mytopname="请选择子类名称";
}
var fullObj=document.all(fullname);
var webFileUrl = "?sortid=" + svalue + "&sType=" + sType;
var result = "";
var xmlHttp = new ActiveXobject("MSXML2.XMLHTTP");
xmlHttp.open("POST" ,webFileUrl, false);
xmlHttp.send("");
result = xmlHttp.responseText;
if(result != "" && svalue != "")
{
fullObj.length=0;
fullObj.options.add(new Option(mytopname,""));
var piArray = result.split(",");
for(var i=0;i<piArray.length;i++)
{
var ary1 = piArray[i].toString().split("|");
fullObj.options.add(new Option(ary1[1].toString(),ary1[0],toString()));
}
}
else
{
fullObj.length = 0;
fullObj.options.add(new Option(mytopname,""));
}
if(sType == "1")
{
document.all("bc_DropDownList").length = 0;
document.all("sc_DropDownList").options.add(new Option(mytopname,""));
}
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<INPUT id="classid" type="text" runat="server" NAME="classid" style="display:none;">
<table cellpadding="0" cellspacing="0" width="96%" align="center" border="0">
<tr>
<td style="HEIGHT: 17px">
行业分类:<asp:DropDownList id="bc_DropDownList" runat="server" onchange="redirect(this.options.selectedIndex)"></asp:DropDownList>
行业子类:<asp:DropDownList id="sc_DropDownList" runat="server" onchange="choose(this.options.selectedIndex)"></asp:DropDownList>
<asp:Button id="del_bc" runat="server" Text="删除分类" Width="73"></asp:Button>
<asp:Button id="del_sc" runat="server" Text="删除子类" Width="73"></asp:Button>
</td>
</tr>
<tr>
<td height="16" style="HEIGHT: 16px"></td>
</tr>
<tr>
<td>
添加分类:<asp:TextBox id="bc_add_textbox" runat="server"></asp:TextBox>
<asp:Button id="bc_submit" runat="server" Text="添加分类" Width="73"></asp:Button>
</td>
</tr>
<tr>
<td>
添加子类:<asp:DropDownList id="bc_add_DropDownList" runat="server"></asp:DropDownList>
<asp:TextBox id="sc_add_textbox" runat="server"></asp:TextBox>
<asp:Button id="Button4" runat="server" Text="添加子类" Width="73"></asp:Button>
</td>
</tr>
</table>
</FONT>
</form>
</body>
</HTML>以上代码是从网上找来的,开始的时候运行正常,可是把 id为1 的记录删除后总用sc_DropDownList.SelectedValue总是提不出第二个dropdownlist的值,请各位大侠指点一下,谢谢~~~~~
解决方案 »
- DataList删除数据,操作成功,但前台页不刷新数据
- 【字符串比较问题】有分隔符号比较
- 数据统计系统-->获取上上级的url搜索引擎。求解【真的很难啊】
- 在vs2008里面的新建和打开里面怎么没有web site这个选项呀?
- 从索引 0 处开始,初始化字符串的格式不符合规范。
- 请问这段代码错在哪里?
- 这里有个好的免费空间!请大家赶快注册哦!
- 求一正则表达式
- 生成网站没出现什么错误!但是发布的时候提示这个错误!应该怎么解决
- 我再加100分,微软高手快帮我解决前面那个未解决的问题!拜托!saucer,sumanden、icyer、hgknight你们人呢?
- 制作“搜索”用户控件时,RequiredFieldValidator问题?
- 求助:关于vs.net2003调试问题!
这个时候改变第一个dropdownlist的时候,sc_DropDownList这个跟着改变吗?
我认为与你“可是把 id为1 的记录删除”这个过程是没有关系的;
你可以在页面上放个TextBox控件(加入控件的id为tb),使其背景色(包括前景色)与你的叶面一样(这样做的目的就是使浏览这个叶面的时候看不到他),然后在page_load的过程中加入
sc_dropdownlist.Attributes.Add("onChange","javascript:document.Form1.tb.value=this.options[this.selectedIndex].value;"); 这样就在sc_dropdownlist发生变化的时候,将sc_dropdownlist.selectedvalue值就放入了tb.text中了,所以你就可以取tb.text这个值了。
<INPUT onclick="callToServer();" type="button" value="Call to Server">
Result : <INPUT id="txtResult" >
当点击按钮的时候,将调用JS脚本方法callToServer(),JS脚本如下:
function callToServer()
{
var param = document.getElementById("txtUsername").value;
var context = "";
<% = ClientScript %>
}
function handleResultFromServer(result, context)
{
document.getElementById("txtResult").value = result;
}
handleResultFromServer()方法则负责将从服务器传回的数据写到txtResult这个文本框里面。
再看看服务器端的代码:
public partial class Default_aspx : System.Web.UI.ICallbackEventHandler
{
private String ClientScript
{
get
{
return this.GetCallbackEventReference(this, "param", "handleResultFromServer", "context");
}
}
public string RaiseCallbackEvent(string eventArgument)
{
return "客户端在[" + DateTime.Now.ToString() + "]传送来 [" + eventArgument + "].";
}
}
我们让页面直接实现ICallbackEventHandler接口,然后接口定义的RaiseCallbackEvent()方法中将服务器的时间和传来的数据一起返回回去。
ClientScript属性的作用是,它调用了页面的GetCallbackEventReference()方法,获得了让客户端有能力调用服务器端方法的JS脚本,并输出到页面的callToServer()方法中,这样,点击页面按钮时,就开始执行页面上包含了调用服务器方法的的callToServer()方法。
注意GetCallbackEventReference()方法的参数,在参数中,我们定义了客户端的哪个变量包含了要传递给服务器,服务器方法执行后,调用客户端的哪个方法等信息。GetCallbackEventReference()的详细参看请看这里。
最后,我们这个页面的执行效果就是: 此主题相关图片如下:
删除,而且删除后也应该重新绑定才可以了。楼主的代码是VB语言写的,这个是C#语言的,可以参考一下
http://blog.csdn.net/sunnystar365/archive/2005/09/28/491349.aspx