5
Answers

DropDownList pass parameter

Sarah Nel

Sarah Nel

14y
6.8k
1
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.

error:
Procedure or Function 'GetWidth' expects parameter '@WidthID', which was not supplied.

Can anyone help please?

code behind:

[code]


protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
string widthId =
Server.UrlEncode(form.SelectedValue.ToString());

Response.Redirect(Link.ToWidth(widthId));
}

[/code]

The Link class:

[code]
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));
}

[/code]

Answers (5)