VB.net中的DropDownList [英] DropDownList in VB.net
本文介绍了VB.net中的DropDownList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的页面上有一个下拉列表ctrl.
我编码为代码隐藏文件中的下拉列表设置datasoure.
我的问题是,每当页面回发时dropdownlist数据源都不存在,并且运行以下代码?
我想在页面首次加载后运行代码.
如果 UnitName_ddl.DataSource 是 什么都没有 然后
Dim dt As New DataTable(" )
dt.Columns.Add(" )
dt.Rows.Add(" )
dt.Rows.Add(" )
dt.Rows.Add(" )
UnitName_ddl.DataSource = dt
UnitName_ddl.DataBind()
结束 如果
解决方案
我认为您必须在每个回发事件中重置 datasoure .
请在PostBack的外面写代码
//Write code here.. if(!IsPostback) { //Remove code from here.. }
如果您仍有问题,请告诉我. :)
谢谢,
Imdadhusen
如果您的控件处于活动状态,请尝试page_load事件:
If not ispostback Then Dim dt As New DataTable("Unit_tbl") dt.Columns.Add("UnitName") dt.Rows.Add("--Select UnitName--") dt.Rows.Add("KOTAK") dt.Rows.Add("ICICI BANK LTD") UnitName_ddl.DataSource = dt UnitName_ddl.DataBind End If
如果禁用了viewstate,则每次页面回发时都必须加载您的值.
I have a dropdownlist ctrl in my page.
I code to set datasoure for dropdownlist in codebehide file.
My question is whenever the page is postback the dropdownlist datasource is nothing and the following code run?
I would like to run the code once page first load.
If UnitName_ddl.DataSource Is Nothing Then
Dim dt As New DataTable("Unit_tbl")
dt.Columns.Add("UnitName")
dt.Rows.Add("--Select UnitName--")
dt.Rows.Add("KOTAK")
dt.Rows.Add("ICICI BANK LTD")
UnitName_ddl.DataSource = dt
UnitName_ddl.DataBind()
End If
解决方案
Hi Usankardurai,
I think you will have to reset datasoure at every postback event.
Please write the code out side of the PostBack
//Write code here.. if(!IsPostback) { //Remove code from here.. }
Please do let me know, if you still have problem. :)
Thanks,
Imdadhusen
If you have viewstate active for your control try on page_load event:
If not ispostback Then Dim dt As New DataTable("Unit_tbl") dt.Columns.Add("UnitName") dt.Rows.Add("--Select UnitName--") dt.Rows.Add("KOTAK") dt.Rows.Add("ICICI BANK LTD") UnitName_ddl.DataSource = dt UnitName_ddl.DataBind End If
If viewstate is disabled you have to load your values each time the page is postedback.
这篇关于VB.net中的DropDownList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文