0

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

4

3 回答 3

1

尝试这个

 <asp:DropDownList ID="DDL2" runat="server" Style="font-size: 12px;
                color: #0066cc; font-family: Tahoma; direction: rtl;" Width="100px" 
                AppendDataBoundItems="True" >

消除

  AppendDataBoundItems="True" from above 
于 2013-08-06T09:19:52.220 回答
1

为什么在 P 标签上设置 EnableViewState="False" ?尝试从 P 标签中删除 EnableViewState="False"。

于 2013-08-06T10:37:51.543 回答
0

还添加 ValueField:

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

和页面加载应该是这样的:

If Not IsPostBack Then
DGDataBind()
End If

这是代码中的问题: 因为IsPostBack是属性而不是方法

并且不要使用内联样式,创建一个 css 类然后使用它。如下:

CSS 代码:

<style>
.ddl1
{
    font-size: 12px;
    color: #0066cc; 
    font-family: Tahoma; 
    direction: rtl;
    width=100px;

    }
</style>

HTML代码是:

<asp:DropDownList ID="DDL1" CssClass="ddl1" runat="server">
</asp:DropDownList>

希望对你有帮助

于 2013-08-06T09:33:20.597 回答