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 6820733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:27:36+00:00 2026-05-26T21:27:36+00:00

Half the battle of getting an answer is knowing how to ask the question.

  • 0

Half the battle of getting an answer is knowing how to ask the question. I am not certain I am doing a good job of that but this is my best shot.

I’m trying to bind a ddl with data inside a gridview that is NOT coming from the gridview itself. This is within the EditItemTemplate. The purpose for doing so is to give the user, to start, a selected value and a series of other values from a lookup stored procedure.

I’ll mention here that I have done this successfully before but using an ObjectDataSource. I am trying to avoid that this time and do it entirely from the code behind for now then move it to a data layer later.

Here is what I have so far…

<asp:GridView ID="usersGrid" runat="server"                 
        DataKeyNames="userID" 
        AutoGenerateColumns="false" Width="580" 
        OnRowUpdating="usersGrid_RowUpdating"
        OnRowEditing="usersGrid_RowEditing" 
        OnRowCancelingEdit="usersGrid_RowCancelingEdit"                                   OnRowDeleting="usersGrid_RowDeleting" 
        >

…

<EditItemTemplate>
                <div class="gridName">
                    <asp:TextBox ID="txtFirstName" Text='<%#Eval("firstName") %>' runat="server" Width="95" />
                </div>
                <div class="gridName">
                    <asp:TextBox ID="txtLastName" Text='<%#Eval("lastName") %>' runat="server" Width="95" />
                </div>
                <div class="gridEmail">
                    <asp:TextBox ID="txtEmail" Text='<%#Eval("email") %>' runat="server" Width="245" />
                </div>
                <div class="gridName">
                    <asp:DropDownList ID="ddl_GetLists" 
                    DataSourceID="GetListData()"
                    AppendDataBoundItems="true"
                    DataValueField="listID"
                    DataTextField="listName"
                    SelectedValue='<%#Bind("listID") %>'
                    runat="server"
                    >
                    </asp:DropDownList>
                </div>
            </EditItemTemplate>

….

Protected Sub usersGrid_RowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs)
    usersGrid.EditIndex = e.NewEditIndex
    BindData()

End Sub

….

Private Sub BindData()
    Dim conn As New SqlConnection(connectionString)
    Dim ad As New SqlDataAdapter("MAINT_DIST_GET_USERS", conn)
    Dim ds As New DataSet()
    ad.Fill(ds)
    GetListData()
    usersGrid.DataSource = ds
    usersGrid.DataBind()

End Sub

I’m including last two as well as other approaches I’ve tried and failed.

…

    Protected Sub usersGrid_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
    If e.Row.RowState = DataControlRowState.Edit Then
        Dim ddl As DropDownList = DirectCast(e.Row.FindControl("ddl_GetLists"), DropDownList)

        Dim conn As New SqlConnection(connectionString)
        Dim ad As New SqlDataAdapter("MAINT_DIST_GET_LISTS", conn)
        Dim ds As New DataSet()
        ad.Fill(ds)

        ddl.DataSource = ds
        ddl.DataBind()
    End If
End Sub

Public Function BindDropdown() As DataSet
    Dim conn As New SqlConnection(connectionString)
    Dim ad As New SqlDataAdapter("MAINT_DIST_GET_LISTS", conn)
    Dim ds As New DataSet()
    ad.Fill(ds)

    ddl_GetLists.DataSource = ds
    ddl_GetLists.DataBind()
End Function

I’ll also ask why, in the final function, why is the control, ddl_GetLists, not recognized as well? Inside the grid it disappears from the designer but outside of the grid it reappears.

Thank you all for your help.

  • 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-05-26T21:27:36+00:00Added an answer on May 26, 2026 at 9:27 pm

    You have a couple of options. You can use a datasource control, or you can bind the dropdowns in code-behind in the RowDataBound event of the GridView.

    I noticed a couple of issues in your code too. In your example you’re assigning the DataSourceID incorrectly. The DataSourceID should point to the ID of a datasource control on the page:

    <asp:DropDownList ID="ddl_GetLists"     
        DataSourceID="SqlDataSource1"    
        AppendDataBoundItems="true"    
        DataValueField="listID"    
        DataTextField="listName"    
        SelectedValue='<%#Bind("listID") %>'    
        runat="server">    
    </asp:DropDownList>
    
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"                  
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>"                  
        SelectCommand="SELECT listID, listName FROM SomeTable">                                             
    </asp:SqlDataSource> 
    

    If you want to do the binding in code-behind, you can do this through the RowDataBound event:

    Protected Sub GridView1_RowDataBound(sender As Object, e As GridViewRowEventArgs)
        If e.Row.RowType = DataControlRowType.DataRow AndAlso (e.Row.RowState And DataControlRowState.Edit) = DataControlRowState.Edit Then
            Dim ddl As DropDownList = TryCast(e.Row.FindControl("ddl_GetLists"), DropDownList)
            If ddl IsNot Nothing Then
                ddl.DataSource = RetrieveDataSource()
                ddl.DataBind()
            End If
        End If
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I half realize that this question is probably asked already, but I'm not familiar
I have spent about half a day searching for an answer to this question
I spent half an hour finding the answer to this question. Posting it here
I find half solutions everywhere but I cannot get a real answer for this.
(FYI: This question is half thoretical. It is not something which I am definatly
After half an hour searching for an answer to this, I can't think of
This question solves half of my problem because my sliding window can move outside
( I feel this question half belongs here and half on Server Fault; please
This is perhaps a half-baked idea, but can I copy the environment of an
First off: I searched half the web to find an answer with this as

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.