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. binding drop down lists in editable datagrids

binding drop down lists in editable datagrids

Scheduled Pinned Locked Moved ASP.NET
helpwpfwcftutorial
2 Posts 2 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.
  • G Offline
    G Offline
    gamerPotatoe
    wrote on last edited by
    #1

    I have an editable datagrid with some textboxes and a drop down list in editable mode. The thing is that I know how to bind data to the textboxes so that when ever I click the edit button on the datagrid the textboxes appear with the default data of the correspondiong cell. However I'm stuck with trying to implement the same for the drop down list. I would appreciate any form of help on this. :-D

    M 1 Reply Last reply
    0
    • G gamerPotatoe

      I have an editable datagrid with some textboxes and a drop down list in editable mode. The thing is that I know how to bind data to the textboxes so that when ever I click the edit button on the datagrid the textboxes appear with the default data of the correspondiong cell. However I'm stuck with trying to implement the same for the drop down list. I would appreciate any form of help on this. :-D

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

      Hi there, To use a dropdownlist control when the datagrid is set in edit mode, you simply use a template column and specify a dropdownlist control in the EditItemTemplate element. To bind data to the dropdownlist, you either specify the DataSource property at design time:

      asp:TemplateColumn
      ...
      <EditItemTemplate>
      <asp:DropDownList Runat="server" ID="DropDownList1" DataSource="<%# DDLDataSource() %>">
      </asp:DropDownList>
      </EditItemTemplate>
      </asp:TemplateColumn>

      //The sample code in code-behind
      public string[] DDLDataSource()
      {
      string[] source = new string[3]{"Manager", "Superuser", "User"};

      return source;
      

      }

      or do that in code at runtime, the sample code looks like this:

      private void DataGrid1_EditCommand(object source, DataGridCommandEventArgs e)
      {

      DataGrid1.EditItemIndex = e.Item.ItemIndex;
      
      //You code here to rebind the DataGrid.
      ...
      
      //I assume you want to use a dropdownlist for the first column
      DataGridItem item = DataGrid1.Items\[e.Item.ItemIndex\];
      DropDownList ddl = (DropDownList)item.Cells\[1\].FindControl("DropDownList1");
      ddl.DataSource = DDLDataSource();
      ddl.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