本文介绍了VB.net中的DropDownList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面上有一个下拉列表ctrl.

我编码为代码隐藏文件中的下拉列表设置datasoure.

我的问题是,每当页面回发时dropdownlist数据源都不存在,并且运行以下代码?

我想在页面首次加载后运行代码.


 如果 UnitName_ddl.DataSource  什么都没有 然后
                 Dim  dt  As   New  DataTable("  Unit_tbl" )
                dt.Columns.Add("  UnitName" )
                dt.Rows.Add(" -选择UnitName-" )
                dt.Rows.Add("  KOTAK" )
                dt.Rows.Add("  ICICI BANK LTD" )
                UnitName_ddl.DataSource = dt
                UnitName_ddl.DataBind()
            结束 如果 
解决方案



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
解决方案



这篇关于VB.net中的DropDownList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 21:04
查看更多