why you set EnableViewState="False" on P tag ? try with removing EnableViewState="False" from P tag.
vb.net dropdownlist looses it's datasource on pageload or postback
-
23-06-2022 - |
题
I have a problem with dropdownlist when a button is pressed the bounded data will disappear!
I have absolutely no idea why this is like this!
I have other page that has a bound dropdownlist data as well and it works great but this one get disappear bounded content on page load after pressing the button!
As requested here's my full .vb code
As My files are huge I'm giving you the full link to these files
http://www.mediafire.com/view/8v5e5yjkdpg5780/admin_report.aspx.vb
http://www.mediafire.com/view/xlgt7c2v523rsti/admin_report.aspx
thanks in advance
解决方案
其他提示
Try this
<asp:DropDownList ID="DDL2" runat="server" Style="font-size: 12px;
color: #0066cc; font-family: Tahoma; direction: rtl;" Width="100px"
AppendDataBoundItems="True" >
REMOVE
AppendDataBoundItems="True" from above
add ValueField also:
Sub DGDataBind()
Dim adapter As Data.SqlClient.SqlDataAdapter
adapter = New Data.SqlClient.SqlDataAdapter("LoadSomething", connection)
adapter.SelectCommand.CommandType = Data.CommandType.StoredProcedure
Dim param As New Data.SqlClient.SqlParameter("@something1", Data.SqlDbType.Bit)
param.Value = 1
adapter.SelectCommand.Parameters.Add(param)
param = New Data.SqlClient.SqlParameter("@something2", Data.SqlDbType.Bit)
param.Value = 0
adapter.SelectCommand.Parameters.Add(param)
GlobalVariables.datas.Clear() 'Public Class GlobalVariables Public Shared datas As New Data.DataSet
adapter.Fill(GlobalVariables.datas)
DDL1.DataSource = GlobalVariables.datas.Tables(0)
DDL1.DataTextField = "rptname"
DDL1.DataValueField = "ColumnName"
DDL1.DataBind()
DDL1.Items.Insert(0, New ListItem("empty", "0"))
DDL1.SelectedIndex = 0
DDL2.DataSource = GlobalVariables.datas.Tables(0)
DDL2.DataTextField = "rptname"
DDL2.DataValueField = "ColumnName"
DDL2.DataBind()
End Sub
and page load should be like:
If Not IsPostBack Then
DGDataBind()
End If
Here is the Problem In Your Code: As IsPostBack is Property not a method
and don't use inline style, create a css class then use it. as below:
CSS Code:
<style>
.ddl1
{
font-size: 12px;
color: #0066cc;
font-family: Tahoma;
direction: rtl;
width=100px;
}
</style>
and HTML code is:
<asp:DropDownList ID="DDL1" CssClass="ddl1" runat="server">
</asp:DropDownList>
hope this will help you