473,387 Members | 1,619 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.DataSource = Nothing ???

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 SelectedIndexChanged occurs, if I set a BreakPoint in the
event and I check the values in the Watch window, I can see that the
DataSource property still contain the DataSet. When I set the DataSource of
a DropDownList to my object collection and check the values in the Watch
window when the SelectedIndexChanged occurs, the DataSource is set to
Nothing. Why? What appen to my object? Is my object need something so that
the DataSource property of the DropDownList can retain my object collection?
Hope that someone can help me.

Here are some parts of my code of my object collection. I have a VTBCodes
class that is a collection. I allso have VTBCode class that represent the
data. VTBCodes inherits from PAICollectionBase and implements iEntitys.
PAICollectionBase inherits from CollectionBase of the .net framework.
VTBCode inherits from EntityBase. EntityBase implements iEntity.

<Serializable()> Public MustInherit Class PAICollectionBase
Inherits CollectionBase
Implements IDisposable

Public MustOverride Function Add(ByVal pObject As Object) As Integer

.....

End Class

Public Interface iEntitys

Function GetData() As iEntitys
....

End Try

<Serializable()> Public Class VTBCodes
Inherits PAICollectionBase
Implements iEntitys

Public Overrides Function Add(ByVal pEntity As Object) As Integer
If TypeOf (pEntity) Is VTBCode Then
....
Else
Dim ex As New Exception("...
Throw ex
End If
....

Public Overloads Function GetData() As PAIiFactory.iEntitys Implements
PAIiFactory.iEntitys.GetData
Dim oconConnection As System.Data.SqlClient.SqlConnection
Dim odrVTBCode As System.Data.SqlClient.SqlDataReader = Nothing

oconConnection = Me.GetConnection

Dim strSQL As String = "Select...

odrVTBCode = SqlHelper.ExecuteReader(oconConnection, CommandType.Text,
strSQL)

While odrVTBCode.Read
oVTBCode = New VTBCode

oVTBCode.Desc.Value =
odrVTBCode.Item(oVTBCode.Desc.AliasName(False))

list.Add(oVTBCode)

End While

Return Me
....

End Class

Public Interface iEntity

Sub UpdateData(ByVal pConnection As
System.Data.SqlClient.SqlConnection, ByVal pTrans As
System.Data.SqlClient.SqlTransaction)

Sub DeleteData(ByVal pConnection As
System.Data.SqlClient.SqlConnection, ByVal pTrans As
System.Data.SqlClient.SqlTransaction)

Sub InsertData(ByVal pConnection As
System.Data.SqlClient.SqlConnection, ByVal pTrans As
System.Data.SqlClient.SqlTransaction)
....

End Interface

Public MustInherit Class EntityBase
Implements iEntity
Implements IDisposable

Public MustOverride Function GetData(ByVal pExpressionCollection As
iExpression) As iEntity Implements PAIiFactory.iEntity.GetData

Public MustOverride Overloads Sub UpdateData(ByVal pConnection As
System.Data.SqlClient.SqlConnection, ByVal pTrans As
System.Data.SqlClient.SqlTransaction) Implements
PAIiFactory.iEntity.UpdateData

Public MustOverride Overloads Sub DeleteData(ByVal pConnection As
System.Data.SqlClient.SqlConnection, ByVal pTrans As
System.Data.SqlClient.SqlTransaction) Implements
PAIiFactory.iEntity.DeleteData

Public MustOverride Overloads Sub InsertData(ByVal pConnection As
System.Data.SqlClient.SqlConnection, ByVal pTrans As
System.Data.SqlClient.SqlTransaction) Implements
PAIiFactory.iEntity.InsertData

....

End Class

<Serializable()> Public Class VTBCode
Inherits EntityBase

Private mfldDescFr As FieldString
....

Public Sub New()

mfldDesc = New FieldString("Desc", Me, "Desc", 100)'Name , Me,
AlisaName, Length
...

End Sub
....
Public Property Desc() As FieldString
Get
Return mfldDesc

End Get
Set(ByVal Value As FieldString)
mfldDesc = Value

End Set

End Property
....

Public Overrides Function GetData(ByVal pExpressionCollection As
iExpression) As iEntity
....

Public Overrides Function ToString() As String

'This will show the value in the DropDownList
Return Convert.ToString(mfldDesc.Value)

End Function
....

End Class

This is the code to fill the DropDownList

Dim oVTBCodes As New VTBCodes

cboCodeDivision.DataSource = oVTBCodes.GetData
cboCodeDivision.DataBind()
Nov 19 '05 #1
2 2906
"cboCodeDivision.DataSource = oVTBCodes.GetData
cboCodeDivision.DataBind() "

Be sure to set the DataText and DataValue properties of your drop-down:

cboCodeDivision.DataTextField = "FieldName"
cboCodeDivision.DataValueField = "FieldName"

Also, when the page reloads, its datasource will be nothing; so try
storing the dataset in the page cache if you need to retrieve it later:

Cache.Insert("keynamefordataset",dataset)

You can get it back:
dataset = ctype(Cache.Item("keynamefordataset"),dataset)

(I use "dataset" here for, really, any object).

Even though the datasource of your dropdown goes to Nothing, the text
and value properties you set at databinding time will still be
available:

cboCodeDivision.SelectedItem.Text and
cboCodeDivision.SelectedItem.Value

Hope this is helpful....
zdrakec

Nov 19 '05 #2
Thank you. It help me :-)
Bye

"zdrakec" <zd*****@yahoo.com> a écrit dans le message de news:
11*********************@g47g2000cwa.googlegroups.c om...
"cboCodeDivision.DataSource = oVTBCodes.GetData
cboCodeDivision.DataBind() "

Be sure to set the DataText and DataValue properties of your drop-down:

cboCodeDivision.DataTextField = "FieldName"
cboCodeDivision.DataValueField = "FieldName"

Also, when the page reloads, its datasource will be nothing; so try
storing the dataset in the page cache if you need to retrieve it later:

Cache.Insert("keynamefordataset",dataset)

You can get it back:
dataset = ctype(Cache.Item("keynamefordataset"),dataset)

(I use "dataset" here for, really, any object).

Even though the datasource of your dropdown goes to Nothing, the text
and value properties you set at databinding time will still be
available:

cboCodeDivision.SelectedItem.Text and
cboCodeDivision.SelectedItem.Value

Hope this is helpful....
zdrakec

Nov 19 '05 #3

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

Similar topics

12
by: Stanley J Mroczek | last post by:
How do you load a dropdownlist when edit is clicked in a datagrid ? <Columns> <asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True" HeaderText="Option...
2
by: rmorvay | last post by:
I am trying to dynamically build a dropdownlist and bind it to a cell in a grid. I tried to utilize the following code but I am stuck at the point where I bind the dropdownlist to the grid cell. ...
5
by: DC Gringo | last post by:
I have a dropdownlist that, upon form submission, I'd like to maintain the selected value when I get my result...how do I do that? <asp:dropdownlist Font-Size="8" id="ddlCommunities"...
1
by: Darren | last post by:
hi i have got a dropdownlist in a templatecolumn and I am trying to load it with values. this is the code in the testGrid_EditCommand function testGrid.EditItemIndex = e.Item.ItemIndex;...
3
by: Richard | last post by:
I've seen articles on GotDotNet and elsewhere on how to put a ddl in a datagrid, and have been able to implement this technique. For a new item, among the datagrid columns there is the one ddl for...
2
by: Paul Owen | last post by:
Hmm, nobody seems to want to answer any of my questions, but here goes again! I have a Detailview control that is bound to a data source. Within the Detailview control I have a number of...
3
by: troy.forster | last post by:
I am sure this must be about the simplest thing to do. I can whip something off in 10 different languages and environments with no problem. But VisualStudio 2003 and ASP.NET is sooooo...
1
by: jimb | last post by:
I can get the dropdownlist into the datagrid, and I can populate it, but I can't read it. Anybody have a working example of a dropdownlist in an editable grid? Thanks. -- .....
0
by: RosH | last post by:
Hi Everyone, I have a CreateUserWizard my public sign up page of my website. I have edited the wizard to include collection of other personal information. I have a DropDownList for the...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.