Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8875465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:58:52+00:00 2026-06-14T18:58:52+00:00

I am trying to populate a gridview with columns that contain a dropdownlist using

  • 0

I am trying to populate a gridview with columns that contain a dropdownlist using asp.net.

So far I am able to populate the dropdownlist with all options from a SQL table and I am also able to save and read the selected values from a SQL table except for the very last row it just seems to ignore it.

Heres my code:

Protected Sub gridGenerators_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gridGenerators.RowDataBound

    With e.Row
        If e.Row.RowType = DataControlRowType.DataRow Then

            'Populate all dropdown lists with options from SQL'
            Dim ddl = TryCast(.Cells(0).FindControl("ddlOnCallGroup"), DropDownList)

            ddl.DataSource = db.getSMSgroups()
            ddl.DataTextField = "SMS_Group"
            ddl.DataValueField = "id"
            ddl.DataBind()

            'And add a default when value is NULL'
            Dim l1 As New ListItem

            l1.Text = "-select-"
            l1.Value = ""

            ddl.Items.Add(l1)

            'Get the current setting from SQL (that user has permissions for)'
            Dim generators As String = Membership.GetUser().Comment
            Dim genDT As DataTable = db.locations(generators.Split(",".ToCharArray))

            'Iterate through settings and select value for each dropdownlist'
            For Each grdrow As GridViewRow In gridGenerators.Rows

                Dim drdList = TryCast(gridGenerators.Rows(grdrow.RowIndex).Cells(0).FindControl("ddlOnCallGroup"), DropDownList)

                drdList.SelectedValue = genDT.Rows(grdrow.RowIndex).Item("ID_SMS_Group").ToString

            Next

        End If
    End With

End Sub

Thanks in advance!!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:58:53+00:00Added an answer on June 14, 2026 at 6:58 pm

    Why are you looping all GridViewRows in RowDataBound which is called for every GridViewRow anyway?

    So instead of this loop:

    For Each grdrow As GridViewRow In gridGenerators.Rows
    
        Dim drdList = TryCast(gridGenerators.Rows(grdrow.RowIndex).Cells(0).FindControl("ddlOnCallGroup"), DropDownList)
        drdList.SelectedValue = genDT.Rows(grdrow.RowIndex).Item("ID_SMS_Group").ToString
    
    Next
    

    just this:

    Dim drdList = DirectCast(e.Row.FindControl("ddlOnCallGroup"), DropDownList)
    drdList.SelectedValue = DirectCast(e.Row.DataItem, DataRowView).Item("ID_SMS_Group").ToString
    

    Note that i’ve also changed some other things(like accessing the DataItem or using FindControl on e.Row)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to populate an (editable) gridview in ASP.NET with a table from
Trying to Populate DropDownList when it is clicked (Asp.Net). I have a sample below
Im trying to populate a JSF Datatable with data that I am retrieving from
I am trying to populate a dropdownlist with data pulled from a .resx file.
I am trying to populate the <s:select options using a struts action class. How
I am trying to get a gridview to populate text from the database call
I am trying to populate a list box from a list in python using
I am trying to populate an asp:Menu control using an XML file. I want
I am trying to populate a listview from sqlite database. My code is using
I am trying to populate a gridview using LayoutInflator.. According to me the code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.