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. Datagrid inside Dropdown problem

Datagrid inside Dropdown problem

Scheduled Pinned Locked Moved ASP.NET
helpquestion
6 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.
  • D Offline
    D Offline
    dsrao
    wrote on last edited by
    #1

    Hi All, I have a datagrid, contains 3 columns.2 columns is boundcolumns and 1 is templatecolumn this template column contain Dropdown control.Fields like acct#,name type(Saving,Checking,Corporate etc.).Usally each row of dropdown show whatever the types avaible, but my case i want show 1st row is 2 values,2nd row is 3 values and 3rd row is 1 value.How can i do these situation.is there any way can implement.Please let me know. Thanks & Regards Rao

    M 1 Reply Last reply
    0
    • D dsrao

      Hi All, I have a datagrid, contains 3 columns.2 columns is boundcolumns and 1 is templatecolumn this template column contain Dropdown control.Fields like acct#,name type(Saving,Checking,Corporate etc.).Usally each row of dropdown show whatever the types avaible, but my case i want show 1st row is 2 values,2nd row is 3 values and 3rd row is 1 value.How can i do these situation.is there any way can implement.Please let me know. Thanks & Regards Rao

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

      Hi there, You simply create an event handler for the ItemDataBound event of the DataGrid, in the handler you can specify the datasource which is bound to the dropdownlist control based on the item index. The sample code goes like this:

      private void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
      {
      if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
      {
      DropDownList ddl = e.Item.FindControl("DropDownList1") as DropDownList;

      	//Now you can sepcify the datasource bound to the dropdownlist 
      	//based on the e.Item.ItemIndex.
      	....
      }
      

      }

      D 1 Reply Last reply
      0
      • M minhpc_bk

        Hi there, You simply create an event handler for the ItemDataBound event of the DataGrid, in the handler you can specify the datasource which is bound to the dropdownlist control based on the item index. The sample code goes like this:

        private void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
        if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
        DropDownList ddl = e.Item.FindControl("DropDownList1") as DropDownList;

        	//Now you can sepcify the datasource bound to the dropdownlist 
        	//based on the e.Item.ItemIndex.
        	....
        }
        

        }

        D Offline
        D Offline
        dsrao
        wrote on last edited by
        #3

        Thank you, I need another solution for this grid.I want preselected database values to dropdown. Some rows show on the top of grid for example acctType is Checking and these rows diable it.This grid want do sorting also.Can i place single templatecoumn in grid multiple controls like 1 row is textbox,2nd row radiobutton ,3rd row dropdown etc.. How can i acheive this situations. Thanks & Regards Rao

        M 1 Reply Last reply
        0
        • D dsrao

          Thank you, I need another solution for this grid.I want preselected database values to dropdown. Some rows show on the top of grid for example acctType is Checking and these rows diable it.This grid want do sorting also.Can i place single templatecoumn in grid multiple controls like 1 row is textbox,2nd row radiobutton ,3rd row dropdown etc.. How can i acheive this situations. Thanks & Regards Rao

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

          Can we go with a single TemplateColumn like this?

          asp:TemplateColumn
          <ItemTemplate>
          <asp:TextBox Runat="server"></asp:TextBox>
          <asp:RadioButton Runat="server"></asp:RadioButton>
          <asp:DropDownList Runat="server"></asp:DropDownList>
          </ItemTemplate>
          </asp:TemplateColumn>

          At run time, depending on the index of the item, you can get and disable the controls which are not supposed to be in the row. Another way is to add the control dynamically. Also, you can think of the Repeater control with which you can be flexible in designing the layout, however, it does not support the sorting by default and you need to handle this issue on your own.

          D 1 Reply Last reply
          0
          • M minhpc_bk

            Can we go with a single TemplateColumn like this?

            asp:TemplateColumn
            <ItemTemplate>
            <asp:TextBox Runat="server"></asp:TextBox>
            <asp:RadioButton Runat="server"></asp:RadioButton>
            <asp:DropDownList Runat="server"></asp:DropDownList>
            </ItemTemplate>
            </asp:TemplateColumn>

            At run time, depending on the index of the item, you can get and disable the controls which are not supposed to be in the row. Another way is to add the control dynamically. Also, you can think of the Repeater control with which you can be flexible in designing the layout, however, it does not support the sorting by default and you need to handle this issue on your own.

            D Offline
            D Offline
            dsrao
            wrote on last edited by
            #5

            Thank you. How can i show(Preselect)database value into dropdown. for example 1.Acct# 10 name smith john type Checking. 2.Acct#20 name roger longer type saving. above 2 rows first row preselected values is checking and 2nd saving etc. Thanks & Regards Rao

            M 1 Reply Last reply
            0
            • D dsrao

              Thank you. How can i show(Preselect)database value into dropdown. for example 1.Acct# 10 name smith john type Checking. 2.Acct#20 name roger longer type saving. above 2 rows first row preselected values is checking and 2nd saving etc. Thanks & Regards Rao

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

              You may want something like this custom control: http://www.codeproject.com/aspnet/MultiColDdList.asp[^]

              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