[英]ASP.net Control in FormView ItemTemplate
我在FormView_Product的ItemTemplate中有一个DropDownList控件,如何修改下面的代码以引用我的DropDownList1?
String strQty = DropDownList1.Items[DropDownList1.SelectedIndex].ToString();
码
}
protected void btnBuy_Click(Object sender, EventArgs e)
{
// test to remind customer to login first
if ((string)Session["sFlag"] != "T")
{
Type csType = this.GetType();
ClientScript.RegisterStartupScript(csType, "Error", scriptErrorLogin);
}
else
{
// test to remind customer to login first
if ((string)Session["sFlag"] != "T")
{
Type csType = this.GetType();
ClientScript.RegisterStartupScript(csType, "Error", scriptErrorLogin);
}
else
{
OleDbConnection mDB = new OleDbConnection();
mDB.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data source="
+ Server.MapPath("~/App_Data/webBase.mdb");
OleDbCommand cmd;
//insert item purchased to itemsTable
int intOrderNo = (int)Session["sOrderNo"];
FormViewRow row0 = FormView_Product.Row;
String strProductId = ((Label)row0.FindControl("lblProductId")).Text;
Int32 unitPrice = Convert.ToInt32(((Label)row0.FindControl("lblUnitPrice")).Text);
float floUnitPrice = float.Parse(strUnitPrice);
String strQty = DropDownList1.Items[DropDownList1.SelectedIndex].ToString();
int intQty = int.Parse(strQty);
string strSQL = "INSERT INTO itemsTable(iOrderNo, iProductId, iQty, iUnitPrice)"
+ "VALUES (@OrderNo, @ProductId, @Qty, @UnitPrice)";
cmd = new OleDbCommand(strSQL, mDB);
cmd.Parameters.AddWithValue("@OrderNO", intOrderNo);
cmd.Parameters.AddWithValue("@ProductId", strProductId);
cmd.Parameters.AddWithValue("@Qty", intQty);
cmd.Parameters.AddWithValue("@UnitPrice", floUnitPrice);
mDB.Open();
cmd.ExecuteNonQuery();
mDB.Close();
Response.Redirect("ShoppingCart.aspx");
}
}
}
尝试这个
DropDownList DropDownList1 = (DropDownList)FormView_Product.FindControl("DropDownList1");
String strQty = DropDownList1.SelectedValue;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.