我在我的asp.net頁面上有一個Repeater Control
,我在中繼器控件中有一些標籤和一個dropdownlist
。缺省內容填入Item_Bound
事件的標籤和下拉列表中。現在我想實現如下:在ASP.Net中從Repeater控件內部的PostBack獲取DropDownlist的值
- 當用戶從下拉列表中選擇另一個項目時,應該相應地更新標籤。這裏
我的問題是,作爲我的默認內容從item_bound
到來,它總是過度乘坐從下拉列表中的內容,但如果我把Item_Bound事件中的!IsPostBack
條件,然後在下拉列表中選擇什麼也沒有發生。
我已經使用了OnSelectedIndexChange事件,並且只是在事件內部提供了Response.Write,但由於DropDownlist值覆蓋了本身,所以我沒有得到任何響應。
任何人都可以幫助我解決這個問題。
更新問題:
現在好了,我能夠獲取與從下拉列表中selectedItems中繼標籤的結果,但現在我的問題是我已經綁定內轉發多個結果,即每每行下拉列表,但是當我從另一行中選擇項目時,它仍然採用第一行的值。這裏是我的代碼以供參考:
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;
}
}
}
}
任何人都可以請幫我這個
使用javascript? – zey