locked
How Can add I selected value of DropDownList inside a Repeater to the listbox control in ASP.Net RRS feed

  • Question

  • How can I get the value of the selected item inside the repeater object that I filled from the database, again in the dropdownlist object that I filled from the database?

    How can I transfer the values ​​of the items I selected from these dropdownlist objects to a listbox?

    Thank you...

    **Ilan.aspx**

    <asp:Repeater ID="rptNitelikler" runat="server" OnItemDataBound="rptNitelikler_ItemDataBound">
             <ItemTemplate>
                  <div class="control-group form-group">
                       <label class="form-label text-dark"><%#Eval("nitelik") %></label>
                       <asp:Label ID="id" runat="server" Visible="false" Text='<%#Eval("nid") %>'></asp:Label>
                       <asp:Label ID="lblItem" Visible="false" runat="server" Text="Label"></asp:Label>
                       <asp:DropDownList ID="ddl" CssClass="form-control select2-show-search" data-placehodler="Seç" Width="100%" runat="server">
                       </asp:DropDownList>
                  </div>
             </ItemTemplate>
        </asp:Repeater>

    **Ilan.aspx.cs**

    private void NitelikGetir()
            {
                int ana, alt, kat;
                ana = int.Parse(Session["AnaId"].ToString());
                alt = int.Parse(Session["AltId"].ToString());
                kat = int.Parse(Session["KatId"].ToString());
                using (BayUniEntities ent = new BayUniEntities())
                {
                    var birlestir = (from nk in ent.NITELIKKATEGORI
                                     join an in ent.ANANITELIKLER
                                     on nk.AnaNitelikId equals an.AnaNitelikId
                                     where nk.AnaKategoriId==ana && nk.AltKategoriId==alt && nk.IlanKategoriId==kat
                                     select new { nitelik=an.AnaNitelik, nid=an.AnaNitelikId }).ToList();
    
    
                    rptNitelikler.DataSource = birlestir;
                    rptNitelikler.DataBind();
                }
            }
    
            protected void rptNitelikler_ItemDataBound(object sender, RepeaterItemEventArgs e)
            {
                int id = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "nid"));
                DropDownList selectList = e.Item.FindControl("ddl") as DropDownList;
                Label lblItem = e.Item.FindControl("lblItem") as Label;
                if (e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem)
                {
                    using (BayUniEntities ent = new BayUniEntities())
                    {
                        var birlestir = (from an in ent.ALTNITELIKLER
                                         where an.AnaNitelikId == id
                                         select an).ToList();
    
                        selectList.DataSource = birlestir;
                        selectList.DataTextField = "AltNitelik";
                        selectList.DataValueField = "AltNitelikId";
                        selectList.DataBind();
                    }
                }
            }





    • Edited by m.akifkrpnr Thursday, June 18, 2020 9:27 AM
    • Moved by CoolDadTx Thursday, June 18, 2020 1:57 PM ASP.NET related
    Thursday, June 18, 2020 8:56 AM

All replies

  • Hello,

    Use the following forum https://forums.asp.net/ as this forum is for C#, not ASP.NET.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Thursday, June 18, 2020 9:45 AM