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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:20:49+00:00 2026-05-25T17:20:49+00:00

I have an item template in a GridView and I want to create a

  • 0

I have an item template in a GridView and I want to create a dropdown for each row and bind it to a value retrieved from the database.. but I am not sure how to do this.. this is what i have so far.. but not sure where to put the code to populate the drop down per row..

 <ItemTemplate>
     <asp:DropDownList runat="server" ID="ddlMyQuantity" SelectedValue='<%# 
       (DataBinder.Eval(Container.DataItem,"Quantity")) %>'>
     </asp:DropDownList>
  </ItemTemplate>

and in code behind, not sure how to or where to put this so that it is created on every row..

 public void BindMyQuantity()
    {
        for (int i = 1; i < 15; i++)
        {
            ddlMyQuantity.Items.Add(i.ToString());
        }
    }

Also i am not sure if i can do that, but the code is not complaining.. adding SelectedValue in the asp declaration

  • 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-25T17:20:49+00:00Added an answer on May 25, 2026 at 5:20 pm

    You can use OnRowDataBound to dynamically bind your dropdown:

    protected void GridView_RowDataBound(Object sender, GridViewRowEventArgs e)
    {
      if(e.Row.RowType == DataControlRowType.DataRow)
      {
         var dropdownList = (DropDownList)e.Row.FindControl("ddlMyQuantity");
         for (int i = 1; i < 15; i++)
         {
            dropdownList.Items.Add(i.ToString());
         }
         dropdownList.SelectedValue = 
               Convert.ToString(DataBinder.Eval(e.Row.DataItem, "Quantity"));
      }
    }
    

    Add binding:

    <asp:GridView ... OnRowDataBound="GridView_RowDataBound">
        ...
    </asp:GridView>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ASP.NET Website, where, in a GridView item template, automatically populated by
I have a 4 column table of products in template,each item in table has
In my aspx page I have a gridview which displays the value from my
I have a grid control. And I want to access gridview child control from
I dynamically create gridview, and in this grid I have template field also field.HeaderTemplate
i have a checkbox in a template field of a gridview and i want
I have a gridview that contains 2 item template 1-checkbox 2-textbox like this: <asp:GridView
I have a gridview in my asp.net project and i used item template like;
I have a GridView , and the GridView has an item template. Now I
I have a gridview, with some columns. I want to hide one column, but

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.