我有一個網站,其中我有一個下拉列表,在那裏我需要顯示從下拉列表中選擇的包的價格,因爲我有很多產品該頁面和每個人都有包下拉
我不想讓每個選擇的包回發。所以我想用AJAX jQuery實現,我使用中繼控制來顯示產品列表。
下面是我使用的將WebMethod功能:
[System.Web.Services.WebMethod]
public static String FillLabel(int Index)
{
Page pa = HttpContext.Current.CurrentHandler as Page;
Repeater homeRepeater = pa.FindControl("rptProducts") as Repeater;
DropDownList drpUnit = homeRepeater.FindControl("drpQuantity") as DropDownList;
int Unit = int.Parse(drpUnit.SelectedItem.Text.Split(' ')[0].Trim());
HiddenField productId = (homeRepeater.Items[Index].FindControl("hdProductId") as HiddenField);
Package objPackage = new Package();
objPackage.ProductId = Convert.ToInt32(productId.Value);
objPackage.TownId = Globals.DefaultTown;
Label mrp = (homeRepeater.Items[Index].FindControl("lblMRP") as Label);
Label ourPrice = (homeRepeater.Items[Index].FindControl("lblOurPrice") as Label);
Label discount = (homeRepeater.Items[Index].FindControl("lblDiscount") as Label);
double discountPercent = Convert.ToDouble(objPackage.GetProductPackages().Find(item => item.Unit == Unit && item.ProductsInfo.ProductID == objPackage.ProductId).Discount);
string mrpVal = objPackage.GetProductPackages().Find(item => item.Unit == Unit && item.ProductsInfo.ProductID == objPackage.ProductId).MaximumRetailPrice.ToString();
string price = objPackage.GetProductPackages().Find(item => item.Unit == Unit && item.ProductsInfo.ProductID == objPackage.ProductId).SabkaSupermarketPrice.ToString();
mrp.Text = mrpVal;
ourPrice.Text = price;
mrp.Visible = (mrpVal != price);
if (discountPercent > 0)
{
discount.Visible = true;
discount.Text = objPackage.GetProductPackages().Find(item => item.Unit == Unit && item.ProductsInfo.ProductID == objPackage.ProductId).Discount.ToString() + "%<br/> OFF";
}
else
{
discount.Visible = false;
}
return String.Empty;
}
現在我的問題是我無法找到中繼器控制的功能是靜態的,我不能訪問頁面對象找到中繼器控制。
任何人都可以告訴我如何訪問靜態方法中的重複控制?
您無法從靜態頁面訪問。你需要找到一個解決方法,如果你從頁面後面的代碼中進行調用,發送頁面處理程序,如果你使用javascript進行調用,獲取返回並使用javascript更改頁面上的內容。 – Aristos