注册 登录
编程论坛 ASP.NET技术论坛

[求助]怎么编译总是提示System.StackOverflowException

xiaofkg 发布于 2007-11-03 09:57, 768 次点击

Imports System.Data.SqlClient
Imports System.Data
Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
binddropdownlist_DataBinding(sender, e)
End If
End Sub

Protected Sub binddropdownlist_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs) Handles binddropdownlist.DataBinding
Dim strCon As String
Dim strSelect As String
Dim con As SqlConnection
Dim sda As SqlDataAdapter


strCon = "Data Source=.;Initial Catalog=sheet;Integrated Security=True"
con = New SqlConnection(strCon)
strSelect = "select count(id) as id,areaBig from test group by areaBig"
sda = New SqlDataAdapter(strSelect, con)
Dim ds As New DataSet()
sda.Fill(ds, "test")
binddropdownlist.DataSource = ds
binddropdownlist.DataValueField = "id"
binddropdownlist.DataTextField = "areaBig"
binddropdownlist.DataBind()

End Sub

Protected Sub binddropdownlist_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles binddropdownlist.SelectedIndexChanged
Dim strCon As String
Dim con As SqlConnection
Dim strSelect As String
Dim sda As SqlDataAdapter

strCon = "Data Source=.;Initiial Catalog=sheet;Integrated Security=true"
con = New SqlConnection(strCon)
strSelect = "select id,areaSmall from test where areaBig='" + binddropdownlist.SelectedItem.Text + "'"
sda = New SqlDataAdapter(strSelect, con)
Dim ds As New DataSet()
sda.Fill(ds, "test")
DropDownList2.DataSource = ds
DropDownList2.DataValueField = "id"
DropDownList2.DataTextField = "areaSmall"
DropDownList2.DataBind()


End Sub
End Class

5 回复
#2
冰彩虹2007-11-03 11:18
binddropdownlist数据绑定需要放在binddropdownlist_DataBinding事件里嘛?这样写,pageloadk的时候会运行,对binddropdownlist绑定时还会运行,大量的重复运行会占用系统资源的呀

直接提供一个方法不就行了
#3
xiaofkg2007-11-03 14:33
冰彩虹你看清楚了没有啊,binddropdownlist_DataBinding只会运行一次,而且我也写了它的方法,并不存在你所说的问题
#4
xiaofkg2007-11-03 21:07
版主再看看,有什么问题
#5
冰彩虹2007-11-04 19:36
那就不清楚了哦,你设置断点debug跟踪看看吧
#6
xiaofkg2007-11-05 13:54
谢了。不过楼主我觉得这个代码段并不能实现二个dropdownlist的联动,你有什么方法吗?

[此贴子已经被作者于2007-11-5 14:24:30编辑过]


1