Published articles on other web sites*

Published articles on other web sites*

ASP.NET: SQLDataSource QueryString Handling

I have seen a lot of developers using the QueryStringParameter with the SQLDataSource for demo ASP.NET applications. A frequently asked question is how to perform checks in cases where the parameter has the value null or Nothing and supply a default value to it.

You can use two ways:

DefaultValue property of the ASP.NET parameter Object


When a parameter has the value null or no parameter is passed, the DefaultValue is used for the value of the parameter.

Using the SQLDataSource_Selecting event

To validate the value of the QueryStringParameter, handle the Selecting event, as shown below:

protected void objArticlesbyAuthor_Selecting(object sender,
SqlDataSourceSelectingEventArgs e)
if (Request.QueryString['productID'] != null)
e.Command.Parameters['@productID'].Value =
e.Command.Parameters['@productID'].Value = 23;

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...