Monday, March 26, 2012

pass url parameter

Hi,

I want to pass a URL parameter from a hyperlinked column in my datagrid to a data list on another page.

How do I construct the select statement for the datalist page please?

Cheers,

JbDo you mean you want the hyperlink URL to be something like:

/SomeDir/SomePage.aspx?ID=TheValueFromSomeDataSourceField

If so, use a HyperLinkColumn. Set its DataNavigateUrlField to the
DataSource field from where you want the databound data to come from.
Then, set the DataNavigateUrlFormatString to:

"/SomeDir/SomePage.aspx?ID={0}"

Essentially, put {0} in the string wherever you want the actual
database value to appear.

(copy and paste from a scott mitchell usenet posting.. ;-).. )
henkm.

Thanks for the reply but i meant on the other page.

select * from tbltable where class_ID = ??

cheers,
JB
The post var can be retrieved with(c#):

So, you sql is going to be something like:

string sqlSelect = "select * from tbltable where class_ID = " + Request.QueryString["ID"];

is this wat you wanted to see, or do your mean the full page code to retrieve the data and show it?
Careful with that, it is wide open to Sql Injection attacks: what happens if I call youpageurl.aspx?ID=1;delete * from tbltable ?
Well, you lose all your data...
Please consider the use of the SqlParameter object to securely build your Sql queries.
bleroy,

Thanks for pointing this out.

Do you know of any good articles or examples of using the sql parameter object for this case?

Thanks all,
JB
Sure,http://samples.gotdotnet.com/quickstart/aspplus/doc/webdataaccess.aspx#param should be a good start.
What if you want to pass 2 parameter in the DataNavigateURLFormatString like:
/SomeDir/SomePage.aspx?id={0}&id2={1}

Where will you put the second field?

0 comments:

Post a Comment