Setting asp:parameter at runtime - possible?

G

Guest

Hi guys

I have the following AccessDataSource control on my page..

<asp:AccessDataSource ID="adsAllStories" runat="server"
DataFile="~/App_Data/Stories.mdb"
SelectCommand="SELECT StoryID, StoryTitle FROM Stories WHERE
StoryTitle LIKE '?%' ORDER BY StoryID DESC">
<SelectParameters>
<asp:parameter Type="char" DefaultValue="A" Name="AllParam" />
</SelectParameters>
</asp:AccessDataSource>

I also have a code generate A-Z link list, which when clicked reload the
page with the querystring ?id= <whichever letter I click>

I'm trying to change the value of the AllParam property on the datasource
when we read the querystring, but i can only find DefaultValue as a property,
and when I watch it, it says that "DefaultValue does not exist in the current
context".

The code I'm using in Page_PreRender is...

adsAllStories.SelectParameters["AllParam"].DefaultValue = showChar; // a char

I'm not using a querystringparameter because I'm performing other functions
on showChar before I pass it to the SelectParameters.

But.. how can I pass it to the accessDataSource?!?!

Thanks,



Dan
 
M

MasterGaurav \(www.edujini-labs.com\)

I also have a code generate A-Z link list, which when clicked reload the
page with the querystring ?id= <whichever letter I click>
But.. how can I pass it to the accessDataSource?!?!

Why don't you add a "QueryStringParamter"?

<SelectParameters>
<asp:SelectParameter name='SQL_Query_Parameter_Name'
QueryStringField='Query_String_Parameter_Name' />
</SelectParameters>


For your case:
<SelectParameters>
<asp:SelectParameter name='AllParam' QueryStringField='id' />
</SelectParameters>


--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujini-labs.com
-----------------------------------------
 
G

Guest

Gaurav,

I want to do something to the querystring before it's passed into the
accessdatasource. This is why I haven't used to <querystring> option.
 
G

Guest

Howdy,

Handle AccessDataSource.Selecting event.
BTW I'm quessing there is an error in the query:
LIKE '?%' ORDER BY StoryID DESC
should be
LIKE ? & '%' ORDER BY StoryID DESC

Hope this helps
 
W

Walter Wang [MSFT]

Hi Dan,

The AccessDataSource.SelectParameters are used to define parameters. To
change the parameter value at run-time, you need to do this in the
Selecting event and use the Command.Parameters collection:

protected void AccessDataSource1_Selecting(object sender,
SqlDataSourceSelectingEventArgs e)
{
e.Command.Parameters["AllParam"].Value = ...;
}

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top