[英]How to bind the 'SelectedValue' in dropdown in ASP.NET Web Forms C# application from code behind?
[英]How to set SelectParameter in code behind in Asp.net web forms application?
我不斷收到錯誤消息,嘗試使用以下命令時必須聲明標量變量“ @inspIdFk”:
protected void rgInspections_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (GridDataItem item in rgInspections.SelectedItems)
{
hdn_insp_id_pk.Value = item["inspIdPk"].Text;
}
string inspidvalue = hdn_insp_id_pk.Value;
if (HttpContext.Current.User.IsInRole("AKOB") || (HttpContext.Current.User.IsInRole("aMgr")))
{
SqlDataSource sdcRgActExps2 = new SqlDataSource();
sdcRgActExps2.ID = "sdcRgActExps2";
this.Page.Controls.Add(sdcRgActExps2);
sdcRgActExps2.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
sdcRgActExps2.SelectCommand = "SELECT ae.actExpIdPk, ae.inspIdFk, ae.actExpDt, aet.actExpType, ae.actExpQty, ae.actExpRate, ae.actExpBill, (ae.actExpQty * ae.actExpRate) AS subTotal FROM inspActExps ae LEFT JOIN actExpTypes aet ON ae.actExpType = aet.actExpTypeIdPk WHERE ([inspIdFk] = @inspIdFk) AND actExpSecCd = 1 ORDER BY actExpDt";
sdcRgActExps2.SelectParameters.Add("@inspIdFk", inspidvalue);
rgActExps2.DataSource = sdcRgActExps2;
rgActExps2.DataBind();
}
else
{
...
}
}
如何成功設置@inspIdFk的值? 我通過從WHERE子句中刪除inspIdFk = @inspIdFk來驗證查詢確實提取了數據。
據我了解,SqlDataSource.SelectParameters.Add采用的參數名稱不帶“&”號,因此您的添加應如下所示:
sdcRgActExps2.SelectParameters.Add("inspIdFk", inspidvalue);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.