DeveloperBarn Forums

Go Back   DeveloperBarn Forums > Programming & Scripting > .Net Development

Discuss "populate datasource control from DDL" in the .Net Development forum.

.Net Development - Learn about the Microsoft.Net framework and how to create powerful web-based (ASP.net) and client-based (Windows Forms) applications utilizing various languages such as C#, VB.Net, J# and others.


Reply « Previous Thread | Next Thread »
 
LinkBack Thread Tools Display Modes
  #11 (permalink)  
Old June 30th, 2008, 05:55 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 332
Thanks: 23
Thanked 27 Times in 27 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

Quote:
Originally Posted by Shem View Post
@RR: what do you use if ya don't use datasource control?
I would use OnSelectedIndexChanged on the DDL and have a sub in code behind that handles the change and populates the other DDL rather than having a control within the page.

There's no reason why the datasource control method shouldn't work though...
Reply With Quote
Sponsored Links
  #12 (permalink)  
Old June 30th, 2008, 06:09 AM
Shem's Avatar
Contributing Member

 
Join Date: Mar 2008
Posts: 192
Thanks: 24
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

can you give me an example?
Reply With Quote
  #13 (permalink)  
Old June 30th, 2008, 06:18 AM
Shem's Avatar
Contributing Member

 
Join Date: Mar 2008
Posts: 192
Thanks: 24
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

narrowed the error down to where 'name' is being lost/blank

Code:
Private Shared Function FillDataRecord(ByVal myDataRecord As IDataRecord) As Zones
            Dim myZones As Zones = New Zones
            myZones.Idkey = myDataRecord.GetInt32(myDataRecord.GetOrdinal("idkey"))
            myZones.ProjectID = myDataRecord.GetInt32(myDataRecord.GetOrdinal("project_id"))
            myZones.UserID = myDataRecord.GetInt32(myDataRecord.GetOrdinal("userID"))
            myZones.Edited = myDataRecord.GetInt32(myDataRecord.GetOrdinal("edited"))
            myZones.Name = myDataRecord.GetString(myDataRecord.GetOrdinal("name"))
            myZones.Description = myDataRecord.GetString(myDataRecord.GetOrdinal("description"))
            HttpContext.Current.Response.Write("<br />name = " & myDataRecord.GetString(myDataRecord.GetOrdinal("name")) & "<br />")
            HttpContext.Current.Response.Write("idkey = " & myZones.Idkey & "<br />")
            Return myZones
        End Function
This is getting a value:
Code:
HttpContext.Current.Response.Write("<br />name = " & myDataRecord.GetString(myDataRecord.GetOrdinal("name")) & "<br />")
And this does not:
Code:
HttpContext.Current.Response.Write("<br />name = " & myZones.Name & "<br />")

Shem
Reply With Quote
  #14 (permalink)  
Old June 30th, 2008, 06:31 AM
Shem's Avatar
Contributing Member

 
Join Date: Mar 2008
Posts: 192
Thanks: 24
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

just tried this:
Code:
Public Property Name() As String
            Get
                HttpContext.Current.Response.Write("BO Name = " & _name)
                Return _name
            End Get
            Set(ByVal value As String)
                _name = value
            End Set
        End Property
It did NOT return a value
Reply With Quote
  #15 (permalink)  
Old June 30th, 2008, 06:33 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 332
Thanks: 23
Thanked 27 Times in 27 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

Quote:
Originally Posted by Shem View Post
can you give me an example?
.aspx page
Code:
<asp:DropDownList id="DDL1" runat="server" autopostback="True" OnSelectedIndexChanged="DDL1_OnSelectedIndexChanged" />
 
<asp:DropDownList id="DDL2" runat="server" />
Code behind
Code:
Protected Sub DDL1_OnSelectedIndexChanged(ByVal s As Object, By Val e As EventArgs)
 
Dim conn as New MySQLConnection(ConnDal.ConnString)
Dim mycommand as New MySQLCommand("SELECT id,name FROM tbl WHERE primary_id=?id", conn)
Dim rs As MySQLDataReader
 
Try
       mycommand.Parameters.AddwithValue("id",DDL1.SelectedValue)
       conn.open
       rs = mycommand.ExecuteReader()
       if rs.HasRows then
           DDL2.DataSource=rs
           DDL2.DataValueField = "id"
           DDL2.DataTextField = "name"
           DDL2.DataBind()
       end if
       rs.close()
catch ex as Exception
       update_error.visible = True
       update_error.text = ex.ToString
finally
       mycommand.dispose()
       conn.close()
       conn.dispose()
end try
 
end sub
Quote:
Originally Posted by Shem
narrowed the error down to where 'name' is being lost/blank
My guess is it is an error between when you populate the Idkey value and when you populate the name value.

Try moving the myZones.Name code to right underneath the IdKey code.
Code:
myZones.Idkey = myDataRecord.GetInt32(myDataRecord.GetOrdinal("idkey"))
            myZones.Name = myDataRecord.GetString(myDataRecord.GetOrdinal("name"))
            myZones.ProjectID = myDataRecord.GetInt32(myDataRecord.GetOrdinal("project_id"))
            myZones.UserID = myDataRecord.GetInt32(myDataRecord.GetOrdinal("userID"))
            myZones.Edited = myDataRecord.GetInt32(myDataRecord.GetOrdinal("edited"))
            myZones.Description = myDataRecord.GetString(myDataRecord.GetOrdinal("description"))
            Return myZones
        End Function
Reply With Quote
  #16 (permalink)  
Old June 30th, 2008, 06:42 AM
Shem's Avatar
Contributing Member

 
Join Date: Mar 2008
Posts: 192
Thanks: 24
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

moving myZones.Name didn't help, but I have tested and it only populates
the integer fields and not the Text fields?

weird
Reply With Quote
  #17 (permalink)  
Old June 30th, 2008, 06:46 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 332
Thanks: 23
Thanked 27 Times in 27 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

Have you tried just using:-
Code:
If Not IsDBNull(myDataRecord("name")) then myZones.Name = myDataRecord("name")
That's what I use.
Reply With Quote
  #18 (permalink)  
Old June 30th, 2008, 06:57 AM
Shem's Avatar
Contributing Member

 
Join Date: Mar 2008
Posts: 192
Thanks: 24
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

didn't change a thing
man, this is frustrating the living heck outta me now!!!
Reply With Quote
  #19 (permalink)  
Old June 30th, 2008, 07:07 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 332
Thanks: 23
Thanked 27 Times in 27 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

Are you using MySQL or MS SQL?

I found

this
on the MySQL website, but looks like it's all been resolved.

Would any of the records contain a NULL value for any of the fields you're returning?
Reply With Quote
  #20 (permalink)  
Old June 30th, 2008, 07:30 AM
jmurrayhead's Avatar
Your Lord & Master

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 543
Thanks: 14
Thanked 41 Times in 40 Posts
Blog Entries: 2
Rep Power: 1
jmurrayhead will become famous soon enough

Awards Showcase
Microsoft SQL Server Microsoft Windows Microsoft .Net Classic ASP 
Total Awards: 4

Default

shem, try debugging your app: Walkthrough: Debugging Web Pages in Visual Web Developer

I would start off with setting a breakpoint on the FillDataRecord function and see if a value is actually being set or not.
__________________
jmurrayhead
Did I help you out? Make me popular by clicking the icon!

If you found a post helpful, please click the button in the lower right-hand corner of the post.

Powered by ASP.Net
Reply With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > .Net Development

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
populate combobox from another Jaykappy Microsoft Access 4 May 7th, 2008 02:56 PM
WebCharts Control richyrich .Net Development 1 April 4th, 2008 11:14 AM


Sponsored Links

ASP.NET Resource Index
a directory of ASP.NET tutorials, applications, scripts, assemblies and articles for the novice to professional developer.

Free Web Directory
Including Chats and Forums Resources, Offer automatic, instant and free directory submissions.
URLZ Web Directory
URLZ Web Directory

Free Web Directory - Add Your Link
The Little Web Directory
Free Web Directory
Pegasus free web directory is a free directory organised by categories.

Web Directory & SEO Services
dirroot web directory


All times are GMT -4. The time now is 12:33 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
Copyright © 2008 DeveloperBarn.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46