Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. populating dropdownlist within a datagrid

populating dropdownlist within a datagrid

Scheduled Pinned Locked Moved ASP.NET
tutorialdatabasequestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    viktor9990
    wrote on last edited by
    #1

    I wonder how to do in order to populate a dropdownlist (with data from database) within a datagrid on page Load. Notice that I want the dropdownlists to be populated within the datagrid without that the datagrid is in edit mode.Any example code? Thanks.

    M A 2 Replies Last reply
    0
    • V viktor9990

      I wonder how to do in order to populate a dropdownlist (with data from database) within a datagrid on page Load. Notice that I want the dropdownlists to be populated within the datagrid without that the datagrid is in edit mode.Any example code? Thanks.

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      Hi there, You can find this site DatagridGirl[^] as a good place to look for an example regarding to your issue.

      1 Reply Last reply
      0
      • V viktor9990

        I wonder how to do in order to populate a dropdownlist (with data from database) within a datagrid on page Load. Notice that I want the dropdownlists to be populated within the datagrid without that the datagrid is in edit mode.Any example code? Thanks.

        A Offline
        A Offline
        Anish Gopi
        wrote on last edited by
        #3

        In order to populate a dropdownlist with in a datagrid. Create a template coloumn and add a DropDownlist in ItemTemplate section. To bind data Specify DataTextField DataValueField DataSource

        <asp:DataGrid id="DataGrid1" runat="server"
        AutoGenerateColumns="False" Width="184px" Height="176px">
        <Columns>
        <asp:BoundColumn DataField="Name" HeaderText="Name"></asp:BoundColumn>
        <asp:TemplateColumn HeaderText="Designation">
        <ItemTemplate>
        <asp:DropDownList id=ddlList runat="server" Width="184px"
        DataSource="<%#PopulateList()%>" DataTextField="Name" DataValueField="ID">
        </asp:DropDownList>
        </ItemTemplate>
        </asp:TemplateColumn>
        </Columns>
        </asp:DataGrid>

        An alternate way to do using code is by mapping ItemDataBound Event

        private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
        if (e.Item.ItemType == ListItemType.Item)
        {
        DropDownList ddlLst = (DropDownList) e.Item.FindControl("ddlList");
        ddlLst.DataValueField = "ID";
        ddlLst.DataTextField = "Name";
        ddlLst.DataSource = PopulateList();
        ddlLst.DataBind();
        }
        }

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups