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

  • Thread starter Thread starter m.akifkrpnr
  • Start date Start date
M

m.akifkrpnr

Guest
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();
}
}
}

Continue reading...
 
Back
Top