I have a Repeater Control on one of my asp.net page, i have some labels and one dropdownlist in the repeater control. Default contents are filled in the label and dropdownlist from the Item_Bound event. Now i want to achieve below:
- When user selects another item from the dropdownlist, the labels should be updated accordingly.
My Problem here is, as my default content is coming from the item_bound, it always over-rides the content from the dropdownlist, but if i place the !IsPostBack condition inside Item_Bound event, then on selecting dropdownlist nothing happens.
I have used OnSelectedIndexChange event, and just providing the Response.Write inside the event, but as the DropDownlist values overrides itself, i don't get anything on the response.
Can anyone help me with the logic about how shall i tackle this.
Updated Question:
Ok now i am able to fetch the results in the repeater label with the selectedItems from dropdown, but now my problem is i have binded multiple results inside repeater, i.e. each dropdowns per row, but when i select items from another row, it still assumes the value of the first row. Here is my code for reference:
protected void drpQuantity_SelectedIndexChanged(object sender, EventArgs e) //DropDown inside repeater control.
{
foreach (RepeaterItem item in rptLatestProducts.Items)
{
if (item.ItemType == ListItemType.Item)
{
HiddenField hd = item.FindControl("hdProductId") as HiddenField;
DropDownList drp = item.FindControl("drpQuantity") as DropDownList;
Label mrp = item.FindControl("lblMRP") as Label;
Label ourPrice = item.FindControl("lblOurPrice") as Label;
Label discount = item.FindControl("lblDiscount") as Label;
ScriptManager.RegisterStartupScript(updPriceByUnits, this.GetType(), "alert", "alert('" + hd.Value + "')", true); //Always returns product id of the first row.
objPackage.ProductId = Convert.ToInt32(hd.Value);
objPackage.TownId = objPackage.DefaultTown;
int discountPercent = Convert.ToInt32(objPackage.GetProductPackages().Select("unit=" + drp.SelectedValue + " and productid=" + hd.Value)[0]["Discount"].ToString());
mrp.Text = "<span class='rupee' style='font-size:14px;'>Rs</span>" + objPackage.GetProductPackages().Select("unit=" + drp.SelectedValue + " and productid=" + hd.Value)[0]["MRP"].ToString();
ourPrice.Text = "<span class='rupee' style='font-size:14px;'>Rs</span>" + objPackage.GetProductPackages().Select("unit=" + drp.SelectedValue + " and productid=" + hd.Value)[0]["Price"].ToString();
mrp.Visible = (mrp.Text != ourPrice.Text);
if (discountPercent > 0)
{
discount.Visible = true;
discount.Text = objPackage.GetProductPackages().Select("unit=" + drp.SelectedValue + " and productid=" + hd.Value)[0]["Discount"].ToString() + "% OFF";
}
else
{
discount.Visible = false;
}
}
}
}
Can anyone please help me with this