473,626 Members | 3,965 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DropDownList.Da taSource = 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 SelectedIndexCh anged 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 SelectedIndexCh anged 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 PAICollectionBa se and implements iEntitys.
PAICollectionBa se inherits from CollectionBase of the .net framework.
VTBCode inherits from EntityBase. EntityBase implements iEntity.

<Serializable() > Public MustInherit Class PAICollectionBa se
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 PAICollectionBa se
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.iEn titys Implements
PAIiFactory.iEn titys.GetData
Dim oconConnection As System.Data.Sql Client.SqlConne ction
Dim odrVTBCode As System.Data.Sql Client.SqlDataR eader = Nothing

oconConnection = Me.GetConnectio n

Dim strSQL As String = "Select...

odrVTBCode = SqlHelper.Execu teReader(oconCo nnection, CommandType.Tex t,
strSQL)

While odrVTBCode.Read
oVTBCode = New VTBCode

oVTBCode.Desc.V alue =
odrVTBCode.Item (oVTBCode.Desc. AliasName(False ))

list.Add(oVTBCo de)

End While

Return Me
....

End Class

Public Interface iEntity

Sub UpdateData(ByVa l pConnection As
System.Data.Sql Client.SqlConne ction, ByVal pTrans As
System.Data.Sql Client.SqlTrans action)

Sub DeleteData(ByVa l pConnection As
System.Data.Sql Client.SqlConne ction, ByVal pTrans As
System.Data.Sql Client.SqlTrans action)

Sub InsertData(ByVa l pConnection As
System.Data.Sql Client.SqlConne ction, ByVal pTrans As
System.Data.Sql Client.SqlTrans action)
....

End Interface

Public MustInherit Class EntityBase
Implements iEntity
Implements IDisposable

Public MustOverride Function GetData(ByVal pExpressionColl ection As
iExpression) As iEntity Implements PAIiFactory.iEn tity.GetData

Public MustOverride Overloads Sub UpdateData(ByVa l pConnection As
System.Data.Sql Client.SqlConne ction, ByVal pTrans As
System.Data.Sql Client.SqlTrans action) Implements
PAIiFactory.iEn tity.UpdateData

Public MustOverride Overloads Sub DeleteData(ByVa l pConnection As
System.Data.Sql Client.SqlConne ction, ByVal pTrans As
System.Data.Sql Client.SqlTrans action) Implements
PAIiFactory.iEn tity.DeleteData

Public MustOverride Overloads Sub InsertData(ByVa l pConnection As
System.Data.Sql Client.SqlConne ction, ByVal pTrans As
System.Data.Sql Client.SqlTrans action) Implements
PAIiFactory.iEn tity.InsertData

....

End Class

<Serializable() > Public Class VTBCode
Inherits EntityBase

Private mfldDescFr As FieldString
....

Public Sub New()

mfldDesc = New FieldString("De sc", 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 pExpressionColl ection As
iExpression) As iEntity
....

Public Overrides Function ToString() As String

'This will show the value in the DropDownList
Return Convert.ToStrin g(mfldDesc.Valu e)

End Function
....

End Class

This is the code to fill the DropDownList

Dim oVTBCodes As New VTBCodes

cboCodeDivision .DataSource = oVTBCodes.GetDa ta
cboCodeDivision .DataBind()
Nov 19 '05 #1
2 2928
"cboCodeDivisio n.DataSource = oVTBCodes.GetDa ta
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("k eynamefordatase t",dataset)

You can get it back:
dataset = ctype(Cache.Ite m("keynameforda taset"),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.T ext and
cboCodeDivision .SelectedItem.V alue

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************* ********@g47g20 00...legro ups.com...
"cboCodeDivisio n.DataSource = oVTBCodes.GetDa ta
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("k eynamefordatase t",dataset)

You can get it back:
dataset = ctype(Cache.Ite m("keynameforda taset"),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.T ext and
cboCodeDivision .SelectedItem.V alue

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
2778
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 Description"></asp:BoundColumn> <asp:TemplateColumn runat="server" HeaderText="Id Type Option" "> <itemtemplate> <asp:label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "TypeOption") %>' /> <asp:label runat="server" ID="LlbTypeOption" Visible=False...
2
2231
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. I get the following message for this code but I suspect that the " UltraWebGrid1.Rows.Cells.Value = ddlGeography;" is not how you bind the dropdownlist control to the grid. ERROR: "The type 'System.Web.UI.WebControls.DropDownList' must be...
5
2658
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" runat="server" Width="100"></asp:dropdownlist> Sub RunReport_OnClick(sender As Object, e As System.EventArgs) _sqlStmt &= " AND tblSurvey1.clnGUID = '" &
1
3358
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; DropDownList list = (DropDownList).Item.FindControl("employees");
3
1806
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 the user to choose an account description, and when the user saves, then the value is saved and displayed in a bound column in the datagrid. So far so good. The problem is when the user edits the line. The ddl is refreshed with all of the...
2
3353
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 dropdownlist controls that I want to list available options but will be bound to the Detailview control. I can achieve all this and seem to select the correct item from the datasource. However, when I try to update, the bound dropdownlist value seems to...
3
1971
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 frustrating!!! My example is simple. I have an Access table (mytable) with two fields of type text (userid and password). I want to display a dropdownlist on a page and have it list the userids. Nothing more.
1
2357
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. -- .. http://sf-f.org, weblog and search engine for fans and writers of
0
2155
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 selection of the Graduation year. Find the code below to Insert all the additional information to another database when a new ASP user is created. The DropDownList gets cleared of all data during execution of this code. Your thoughts on the solution...
0
8266
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8199
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8705
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8638
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8365
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7196
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5574
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2626
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.