473,387 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

DropDownList drops values on window resize?

Hi,

I've bound some drop down lists to a dataset, but if the
iexplorer window is resized the contents of the lists are
lost?

Why is this happening?

AutoPostback is set to true.

TAI

Lionel
Nov 20 '05 #1
6 1180
Cor
Hi Lionel,

Can you send some (aspx.vb) code?

Cor

I've bound some drop down lists to a dataset, but if the
iexplorer window is resized the contents of the lists are
lost?

Nov 20 '05 #2
The function is a generic one where you can pass the
table name and field name to populate the
The code used to populate the list is:

Private Function PopulateDropDownListbox2(ByVal iField As
String, _
ByVal iTable As String, _
ByVal iDDL As DropDownList, _
ByVal iConnection As ADODB.Connection, _
Optional ByVal iDistinct As Boolean = True, _
Optional ByVal iAdditionalQuery As String = "")
As System.Data.DataSet

' Create a recodset from the Connection, use
distinct if required
Dim recs As New ADODB.Recordset, sql As String
If iDistinct = True Then
sql = "Select Distinct " & iField & " from "
& iTable
Else
sql = "Select " & iField & " from " & iTable
End If

' Apply a filter string
If iAdditionalQuery = "" Then
' do nothing
Else
sql = sql & " WHERE " & iAdditionalQuery
End If

' Query the connection
recs = iConnection.Execute(sql)

' Populate a tempory data table and data adapter
Dim dt As New DataTable
Dim da As New System.Data.OleDb.OleDbDataAdapter
da.Fill(dt, recs)

' Create a dataset
Dim ds As New DataSet
ds.Tables.Add(dt)

' Populate and update the Drop Down Listbox
iDDL.DataTextField = iField
iDDL.DataSource = ds.Tables(0)
iDDL.DataBind()

Return ds

' Clear Up
recs = Nothing
dt = Nothing
da = Nothing
ds = Nothing

End Function
Nov 20 '05 #3
Cor
Hi,

I tried your code and changed it a lot.
I made from it in a workingsample situation but had to change a lot.
(It is still not what I would make, but I did not want to change to much
from your originalcode)
I also used sqlclient.sql........ that you can everywhere change in
oledb.oledb....... and then use the right connection string.

I did use the northwind database because I have of course not your database
and therfore I had to remove some things.

Under the sample I give some comments on your code.

I hope this helps?

Cor

\\\
Private Sub Page_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Dim Conn As New SqlClient.SqlConnection _
("Server=xxxxxxx;DataBase=northwind;Integrated Security=SSPI")
PopulateDropDownListbox2("EmployeeID", "Employees",
DropDownList1, Conn, True, )
End If
End Sub

Private Function PopulateDropDownListbox2 _
(ByVal iField As String, _
ByVal iTable As String, _
ByVal iDDL As DropDownList, _
ByVal iConnection As SqlClient.SqlConnection, _
Optional ByVal iDistinct As Boolean = True, _
Optional ByVal iAdditionalQuery As String = "") As
System.Data.DataSet
' Create a recodset from the Connection, use distinct if required
Dim sql As String = "Select EmployeeID, FirstName from Employees"
Dim ds As New DataSet
Dim da As New SqlClient.SqlDataAdapter(sql, iConnection)
da.Fill(ds, iTable)
' Populate and update the Drop Down Listbox
iDDL.DataTextField = iField
iDDL.DataValueField = "Firstname"
iDDL.DataSource = ds.Tables(0)
iDDL.DataBind()
' Clear Up
iConnection.Close()
Return ds
End Function
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = Me.DropDownList1.SelectedValue
End Sub
End Class
///
Private Function PopulateDropDownListbox2(ByVal iField As
String, _
ByVal iTable As String, _
ByVal iDDL As DropDownList, _
ByVal iConnection As ADODB.Connection, _
Optional ByVal iDistinct As Boolean = True, _
Optional ByVal iAdditionalQuery As String = "")
As System.Data.DataSet
Why you make this difficult function. The most important thing the sql
string is not in it, when that was I could understand it, but than you do
not need that two last optional parameters.
' Create a recodset from the Connection, use
distinct if required
Dim recs As New ADODB.Recordset, sql As String
Why you need a recordset you are not using it and set it even to nothing at
the end
If iDistinct = True Then
sql = "Select Distinct " & iField & " from "
& iTable
Else
sql = "Select " & iField & " from " & iTable
End If

' Apply a filter string
If iAdditionalQuery = "" Then
' do nothing
Else
sql = sql & " WHERE " & iAdditionalQuery
End If
See for that my first comment
' Query the connection
recs = iConnection.Execute(sql)

' Populate a tempory data table and data adapter
Dim dt As New DataTable
Dim da As New System.Data.OleDb.OleDbDataAdapter
da.Fill(dt, recs)
You have to file a dataset, just change dt for ds and datatable for datset
but see my code to do it right there are more errors in that

' Create a dataset
Dim ds As New DataSet
ds.Tables.Add(dt) See before and my code

' Populate and update the Drop Down Listbox
iDDL.DataTextField = iField
iDDL.DataSource = ds.Tables(0)
iDDL.DataBind()

Return ds

' Clear Up
recs = Nothing
dt = Nothing
da = Nothing
ds = Nothing
Why is all that setting to nothing I see it nowhere in the documentation

There is no close of the connection.
End Function

Nov 20 '05 #4
Thanks for that, I change the code to use OleDB. This
makes the connection and populates the ddl fine in the
first instance (as did the original code). So, the
problem isn't populating the list in the first place,
but, when the explorer window is resized, the ddl loses
all its values, i.e. the ddl goes blank?

Any more ideas?
Nov 20 '05 #5
Cor
What is your advantage by using a extra DLL?
Nov 20 '05 #6
-----Original Message-----
Thanks for that, I change the code to use OleDB. This
makes the connection and populates the drop down list fine in thefirst instance (as did the original code). So, the
problem isn't populating the list in the first place,
but, when the explorer window is resized, the drop down list losesall its values, i.e. the drop down list goes blank?

Any more ideas?
.

Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: David Logan | last post by:
Hello, I am trying to open a window with a graphic in it and have the window be exactly the correct size of the image. Is there anyway to do this that will work on any browser on any OS???? ...
6
by: David Hayes | last post by:
juglesh <juglesh@nospamRadioKDUG.com> wrote in "Re: how to maximize the browser window that fits the monitor size?" (Saturday, January 01, 2005 3:12 AM): > > >I want to maximize the browser...
4
by: Keith | last post by:
I have this simple scenario. -------- Choose an item ->dropdownlist-> or <a>Create a new item</a> -------- When someone decides to click on the create a new item link, it takes them to a...
1
by: Urmal Patel via .NET 247 | last post by:
I have problem with asp:Dropdownlist. I have a dropdownlist control in Page1.aspx and I want to assign value and Text to dropdown list form Page2.aspx from java script function. I am able to assign...
3
by: Lew Barnesson | last post by:
Hi All, I have looked and looked for an answer to the following problem (without success), and would be very grateful for a solution. The problem: The SelectedIndexChanged event code of an...
2
by: Marc Robitaille | last post by:
Hello, I set the DataSource property of a DropDownList to as DataSet that is filled from a SQLDataAdapter. The AutoPostBack property of that DropDownList is set to True. When the...
4
by: Sevu | last post by:
I am working with ASP.NET.I am using ReportViwer Control to show my report.I like to add dropdownlist with in the reportviewer control. ( Not top to the control some thing like that).I need to...
0
by: lamolap | last post by:
i have 1 gridview , a dropdownlist inside a gridview and a commandfield of (edit, update and cancel) my gidview looks like this Edit Surname Initials ...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.