Solved

Sql Datasource and Parameters

Posted on 2011-09-06
4
332 Views
Last Modified: 2012-05-12
I have not used a sql data source before and I'm doing some updates on an existing web site.
In the basepage class that all of the aspx pages inherit from is a property called Culture of type string.
I added the parameter below, is this correct? Do I need to specify anything else or will it extract the value from the property?
 
            <SelectParameters>
                  <asp:QueryStringParameter Name="ProductID" QueryStringField="prodid" Type="Int32" />
                  <asp:Parameter Name="Culture" Type="String" />
            </SelectParameters>
0
Comment
Question by:JRockFL
  • 2
  • 2
4 Comments
 
LVL 18

Expert Comment

by:ivan_vagunin
ID: 36488540
Hi!
I guess you need to set value for parameter, because it will not be binded automatically:
<asp:Parameter Name="Culture" Type="String"  DefaultValue="<%= this.Culture %>"/>
0
 
LVL 8

Author Comment

by:JRockFL
ID: 36488591
it looks like it is passing that literal value.

This is what it looks like from the sql server trace
exec usp_ListSubProductsByProductID @ProductID=1156,@Culture=N'<%= this.Culture %>'
0
 
LVL 18

Accepted Solution

by:
ivan_vagunin earned 500 total points
ID: 36488667
Yes, sorry. It looks like the expression for Default value gets encoded, so the code is not executed... Here is a solution: http://peterkellner.net/2006/09/18/expressionbuilderidentity/, but I guess this is quite complex.
So one option is to create your own parameter class inherited from asp:Parameter. Another is to init DefaultValue from code behind:
protected void OnInit(EventArgs e)
{
   base.OnInit(e);
   MySqldataSource.SelectParameters["Culture"].DefaultValue = Culture;
}
Look this discussion: http://forums.asp.net/t/1115044.aspx/1?Passing+Parameters+for+SqlDataSource+from+code+behind
0
 
LVL 8

Author Closing Comment

by:JRockFL
ID: 36488730
Awesome, thank you
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
IIS Authorization for Web Service 2 49
Gridview alignment 1 21
jQuery - following an example but can I save data server side? 20 51
Expression Evaluater 3 28
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question