如何知道在page_load时,知道页面上的DropDownList是否被点击?
页面上有多个DropDownList,变化DropDownList选项(已设autopostback为true),如何在页面重新刷新进入page_load时,知道点选哪个DropDownList? 问题点数:50、回复次数:14Top
1 楼javacofe(sa)回复于 2003-12-01 15:04:00 得分 0
把选过的项取出放到session之类里刷新以后再拿出来Top
2 楼acewang(龍芯*Inside!)回复于 2003-12-01 15:04:27 得分 40
你需要它来做什么?
是要关联显示?Top
3 楼xmvb(gqxm)回复于 2003-12-01 15:09:56 得分 0
to acewang:
是的Top
4 楼acewang(龍芯*Inside!)回复于 2003-12-01 15:16:03 得分 0
dd1 dd2 :
<asp:DropDownList ID=dd1 runat=server OnSelectedIndexChanged="IndexChanged" ...
编写dd1的SelectedIndexChanged事件:
private void IndexChanged(Sender Object,EventArgs e)
{
//通过dd1.SelectedItem.Text/Value绑定dd2
//dd2.DataSource=
//dd2.DataBind();
}Top
5 楼xmvb(gqxm)回复于 2003-12-01 15:22:21 得分 0
to acewang:
我的代码如下,请帮忙看看。
选择DropDownList1后,屏幕一遍空白。我知道是动态控件不能重新绑定的原因,但不知如何处理。
Protected WithEvents Panel1 As System.Web.UI.WebControls.Panel
Dim test1 As New test1()
Dim ddl_1 As New DropDownList()
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack() Then
calltest()
Else
If Not (Request.Form(ddl_1.UniqueID) Is Nothing) Then
calltest()
End If
End If
End Sub
Sub calltest()
test1.test(Panel1)
ddl_1 = Panel1.FindControl("ddl1")
AddHandler ddl_1.SelectedIndexChanged, AddressOf SelectionChanged
End Sub
Sub SelectionChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim ddl As DropDownList = CType(sender, DropDownList)
Dim s As String = ddl.SelectedItem.Value
Dim ddl2 As DropDownList = CType(Panel1.FindControl("ddl2"), DropDownList)
ddl2.Items.Clear()
Dim i As Integer
For i = 1 To 10
ddl2.Items.Add(New ListItem(s & i, s & i))
Next
End Sub
test1.vb文件:
Public Class test1
Public Sub test(ByRef panel1 As Panel)
Dim ddl As New DropDownList()
ddl.ID = "ddl1"
ddl.AutoPostBack = True
panel1.Controls.Add(ddl)
Dim ddl2 As New DropDownList()
ddl2.ID = "ddl2"
panel1.Controls.Add(ddl2)
Dim i As Integer
For i = 1 To 10
ddl.Items.Add(New ListItem(i & ""))
Next
End Sub
End Class
Top
6 楼acewang(龍芯*Inside!)回复于 2003-12-01 15:44:10 得分 0
有没有报过错误,
断点调试看看几个关键的地方有没有执行:
If Not (Request.Form(ddl_1.UniqueID) Is Nothing) Then
calltest()
End If
~~~~~
Dim ddl2 As DropDownList = CType(Panel1.FindControl("ddl2"), DropDownList)
~~~~~Top
7 楼BenZ004(仲陵)回复于 2003-12-01 15:52:41 得分 0
你的dropdownlist的AutoPostBack属性有没有设置成True?
要设置的.Top
8 楼xmvb(gqxm)回复于 2003-12-01 16:03:01 得分 0
没有报错,但Request.Form(ddl_1.UniqueID)应该是问题所在,它的值一直为"",但如果DropDownList控件不是动态生成,而是拖拽进来生成的,Request.Form(DropDownList1.UniqueID)是可以被赋值的。Top
9 楼acewang(龍芯*Inside!)回复于 2003-12-01 16:15:03 得分 0
ddl_1.UniqueID这个应该不能准确找到DropDownList,应该是ClientID,
Top
10 楼xmvb(gqxm)回复于 2003-12-01 16:48:04 得分 0
换成ddl_1.ClientID也是""值,Top
11 楼xmvb(gqxm)回复于 2003-12-02 08:58:55 得分 0
我之所以要用这种古怪的方法,是有苦衷的,具体原因我另开了一个帖子,有劳你百忙之中跟进一下:http://expert.csdn.net/Expert/topic/2515/2515982.xml?temp=.3599512。
万分感激。
Top
12 楼flygoldfish(长江支流)回复于 2003-12-05 18:13:43 得分 0
if (ddlExpert.SelectedIndex > -1)
{
//初步选了
}Top
13 楼saucer(思归)回复于 2003-12-06 08:16:58 得分 10
you need to re-create the dynamic controls upon each postback and add the control to the Form's Controls hierarchy firstTop
14 楼liuzhonghe(呆头鹅)回复于 2003-12-06 08:34:42 得分 0
你需要在Page_Load事件Page.Controls.Add(test1);Top
相关问题
- 有关showModalDialog关闭子页面后触发父页面的page_load事件!
- aspx 页面的page_load 和 .cs里面的page_load
- 一个页面的Page_Load事件执行两次,
- 关于用window.open()打开指定aspx页面,而被打开的页面却不调用Page_Load()函数问题。
- dropdownlist怎么实现页面跳转
- DropDownList不能跳转页面吗?
- 关于DropDownList页面呈现的问题
- 为什么在aspx页面加入void Page_Load()事件不执行?
- 如何不让页面中Page_load事件重复执行某代码?
- 请问怎么测试页面的加载时间PLT(Page Load Time)?




