Results 1 to 4 of 4

Thread: Weird thing with populating manually a dropdownlist from codebehing.

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2004
    Posts
    36

    Weird thing with populating manually a dropdownlist from codebehing.

    This is weird, at least to me. I have code that populates 2 dropdownlist in a gridview. DropStart And DropEnd I want to add time values depending on a few things here's the routine I cal.

    Code:
    Public Sub GenerateTime(RowIndex As Integer)
    
            Dim ComboStart As New DropDownList
            Dim ComboEnd As New DropDownList
            Dim ItemList As ListItem
            Dim TimeInterval As Integer
            Dim IntervalleCalcul As Integer
            Dim NombreIntervalles As Integer
            Dim HeureCalcule As String
            Dim Laps As Integer
    
            ComboStart = GridDetails.Rows(RowIndex).FindControl("DropStartTime")
            ComboEnd = GridDetails.Rows(RowIndex).FindControl("DropEndTime")
    
            If Not (IsNothing(ComboStart) Or IsNothing(ComboEnd)) Then
    
                ComboStart.Items.Clear()
                ComboEnd.Items.Clear()
                ' --------------------------------------------
                '  DETERMINATION DES PARAMETRES D'INTERVALLES
                ' --------------------------------------------
                Select Case TimeInterval
                    Case 5
                        IntervalleCalcul = 12
                        Laps = 5
                    Case 10
                        IntervalleCalcul = 6
                        Laps = 10
                    Case 15
                        IntervalleCalcul = 4
                        Laps = 15
                    Case 30
                        IntervalleCalcul = 2
                        Laps = 30
                    Case 60
                        IntervalleCalcul = 1
                        Laps = 60
                    Case Else
                        IntervalleCalcul = 4
                        Laps = 15
                End Select
    
                NombreIntervalles = 24 * IntervalleCalcul
                HeureCalcule = "00:00"
                ItemList = New ListItem
                ItemList.Text = HeureCalcule
                ItemList.Value = HeureCalcule
    
                ComboStart.Items.Add(ItemList)
                ComboEnd.Items.Add(ItemList)
                For Compteur = 1 To NombreIntervalles - 1
                    HeureCalcule = CalculerTemps(HeureCalcule, Laps)
                    ItemList = New ListItem
                    ItemList.Text = HeureCalcule
                    ItemList.Value = HeureCalcule
                    ComboStart.Items.Add(ItemList)
                    ComboEnd.Items.Add(ItemList)
                Next Compteur
                ComboStart.DataBind()
                ComboEnd.DataBind()
    
            End If
    
    End Sub
    now this code is called, and runs fine, it goes in the for loop and I see if I trace it that combostart and comboend both have 96 Items in them as expected. hence it did find the controls in the gridview. but when I exit this sub and continue the code by just running the code in the asp.net page the two corresponding dropdown control don't get the values that did get added in the code behind.

    In the RowEditing is when I call this routine.

    Code:
    Private Sub GridDetails_RowEditing(sender As Object, e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridDetails.RowEditing
    
              GridDetails.EditIndex = e.NewEditIndex
            GridDetails.DataBind()
            GenerateTime(GridDetails.EditIndex)
    
    End Sub
    I'm a little more than perplexed by this. lol
    Last edited by MystikShadows; Sep 21st, 2014 at 07:43 PM. Reason: Add where I call my routine from
    When they say it can't be done, THAT's when they call me ;-)

    MystikShadows
    JC-Hosting.net

  2. #2
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: Weird thing with populating manually a dropdownlist from codebehing.

    Try setting the datasource first and then calling databind method. In that case, the dropdownlist control will have values to render.

    See example here: DropDownList MSDN
    There's a section on how to create a DropDownList control though data binding. It's using a datatable as the datasource. You can use a collection object such as List<T> as an alternative.

    KGC
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2004
    Posts
    36

    Re: Weird thing with populating manually a dropdownlist from codebehing.

    To say I did something else, I have created another dropdown, this time a database dropdown, it's not getting it's records either. the SqlDataSource it's bounded to has it's data, but it's not showing it in the gridview's dropdown list. this isn't even code, it's an SQL data source, configured that is bounded to the dropdownlist. very peculiar indeed.


    Quote Originally Posted by KGComputers View Post
    Try setting the datasource first and then calling databind method. In that case, the dropdownlist control will have values to render.

    See example here: DropDownList MSDN
    There's a section on how to create a DropDownList control though data binding. It's using a datatable as the datasource. You can use a collection object such as List<T> as an alternative.

    KGC
    When they say it can't be done, THAT's when they call me ;-)

    MystikShadows
    JC-Hosting.net

  4. #4
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: Weird thing with populating manually a dropdownlist from codebehing.

    Can you post the aspx markup?

    KGC
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width