[英]ASP.Net C# request in retrieving values from input type textbox
因此,我們的小組在檢索輸入類型中輸入的值時遇到問題。 這是我們使用的代碼...
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Session.Remove("clicks");
i = 0;
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
int rowCount = 0;
rowCount = Convert.ToInt32(Session["clicks"]);
rowCount++;
Session["clicks"] = rowCount;
Literal1.Text = Literal1.Text + "PRODUCT: <input type='textbox' runat='server' id='textboxu" + i + "' value='" + GridView1.SelectedRow.Cells[1].Text + "' ></input> PRICE: <input type='textbox' runat='server' size='1' id='textboxe" + i + "' value='" + GridView1.SelectedRow.Cells[2].Text + "' ></input>QUANTITY:<input type='textbox' runat='server' size='1' id='textboxq" + i + "'></input>TOTAL:<input type='textbox' runat='server' size='3' id='total" + i + "' ></input><br>";
i++;
}
protected void Button1_Click(object sender, EventArgs e)
{
for (int check = 0; check <= i; check++)
{
double price = Convert.ToDouble(this.Request.Form["textboxe" + i + ".Value"]);
double quantity = Convert.ToDouble(this.Request.Form["textboxq" + i + ".Value"]);
double total = price * quantity;
TextBox1.Text = Convert.ToString(total);
//this.Request.Form["total" + i] = Convert.ToString(total);
}
}
我們還需要從輸入類型中檢索答案。 我希望有人願意幫助我們...
這些不是服務器控件,因此您應該使用name屬性而不是id。
<input type='textbox' name='textboxu" + i + "' value='" + GridView1.SelectedRow.Cells[1].Text + "' ></input>
...
double textboxu = Convert.ToDouble(this.Request.Form["textboxu" + i]);
為了獲得正確的答案,語法只有少許變化,請參見以下代碼段
double price = Convert.ToDouble(Request.Form["textboxe" + i ]);
double quantity = Convert.ToDouble(Request.Form["textboxq" + i]);
double total = price * quantity;
TextBox1.Text = Convert.ToString(total);
//you need to use only request.Form rather than .value attribute
string szValue = Request.Form["txt1"]
希望能幫助到你
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.