+ Reply to Thread
Page 2 of 3 FirstFirst 1 2 3 LastLast
Results 11 to 20 of 23

Thread: populate datasource control from DDL

  1. #11
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    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...

  2. #12
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    can you give me an example?

  3. #13
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    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

  4. #14
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    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

  5. #15
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    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
    

  6. #16
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

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

    weird

  7. #17
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Have you tried just using:-
    Code:
    If Not IsDBNull(myDataRecord("name")) then myZones.Name = myDataRecord("name")
    
    That's what I use.

  8. #18
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    didn't change a thing
    man, this is frustrating the living heck outta me now!!!

  9. #19
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    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?

  10. #20
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,533
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    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
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


+ Reply to Thread
Page 2 of 3 FirstFirst 1 2 3 LastLast

Similar Threads

  1. populate combobox from another
    By Jaykappy in forum Microsoft Access
    Replies: 4
    Last Post: May 7th, 2008, 03:56 PM
  2. WebCharts Control
    By richyrich in forum .NET Development
    Replies: 1
    Last Post: April 4th, 2008, 12:14 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO