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?
For example, there are 3 dropdownlists in the repeater. I want to transfer the values selected from these dropdownlists to the listbox when I press the button.
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;
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();
}
}
}
To get the selected values from your dropdownlists you need to iterate over the items in the repeater. In your button-handler-code do something like this:
foreach (RepeaterItem repeaterItem in rptNitelikler.Items)
{
DropDownList ddl = (DropDownList)repeaterItem.FindControl("ddl");
if (ddl != null)
{
string selectedValue = ddl.SelectedValue;
// insert code to add value to listbox here.
string selectedText = ddl.SelectedItem.Text;
// Insert code to add Text to listbox here.
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.