将参数从DropDownList传递到存储过程 [英] Pass paramater from DropDownList to Stored Procedure
问题描述
我想在选择一个项目时创建一个下拉列表,将用户重定向到另一个页面并显示有关该项目的内容,所有这些操作都是通过存储过程完成的,但是似乎并没有将参数传递给存储过程.我知道参数没有过去,但我不知道为什么.
错误:
过程或函数"GetWidth"需要未提供的参数"@WidthID".
有人可以帮忙吗?
Hi, I want to create a dropdownlist when an item is selected the user is redirected to another page and content about the item is displayed, all of this is done with stored procedures, but it does not seem to pass parameters to the stored procedure. I know the paramater is not passing but I don''t know ehy not.
error:
Procedure or Function ''GetWidth'' expects parameter ''@WidthID'', which was not supplied.
Can anyone help please?
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string widthId =
Server.UrlEncode(form.SelectedValue.ToString());
Response.Redirect(Link.ToWidth(widthId));
}
private static string BuildAbsolute(string relativeUri)
{
// get current uri
Uri uri = HttpContext.Current.Request.Url;
// build absolute path
string app = HttpContext.Current.Request.ApplicationPath;
if (!app.EndsWith("/")) app += "/";
relativeUri = relativeUri.TrimStart('/');
// return the absolute path
return HttpUtility.UrlPathEncode(
String.Format("http://{0}:{1}{2}{3}",
uri.Host, uri.Port, app, relativeUri));
}
// generate a width URL
public static string ToWidth(string widthId)
{
return BuildAbsolute(String.Format("WidthAdmin.aspx?Width={0}", widthId));
}
这是接收页面,也许我没有正确调用它,原因是如果我不填充GridView,我将不会出现错误
This is the receiving page, maybe I''m not calling it correctly, cause if I don''t populate the GridView I get no errors
protected void Page_Load(object sender, EventArgs e)
{
// load the grid only the first time the page is loaded
if (!Page.IsPostBack)
{
// load the department grid
BindGrid();
}
}
// populate the grid view with data
private void BindGrid()
{
string widthId =
Server.UrlDecode(Request.QueryString["WidthID"]);
// get a DataTable object containing the catalog departments
grid.DataSource = CatalogAccess.GetWidth(widthId);
// bind the data bound controls to the data source
grid.DataBind();
}
推荐答案
return BuildAbsolute(String.Format("WidthAdmin.aspx?Width={0}", widthId));
Server.UrlDecode(Request.QueryString["WidthID"])
您正在使用Width
构建查询,并尝试使用WidthID
对其进行检索.
尼克
You''re building the query with Width
and trying to retrieve it with WidthID
.
Nick
非常感谢尼克,它现在可以工作,您可以救命:-)
Thank you so much Nick it works now, you are a life saver :-)
这篇关于将参数从DropDownList传递到存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!