Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGrid Commands and Passing parameters to URL 2

Status
Not open for further replies.

KevoMee

Technical User
Apr 30, 2002
72
IE
1. Just wondering about DataGrid Commands (as in Delete etc). Can I define my own on a DataGrid? I can't really see how I go about doing this in VS.net

2. Passing parameters to a WebPage: At the moment I use this to pass one parameter:

<asp:HyperLink id=&quot;HyperLink1&quot; runat=&quot;server&quot; Target=&quot;_blank&quot; NavigateUrl='<%# DataBinder.Eval(Container.DataItem, &quot;username&quot;, &quot;UserDetails.aspx?id={0}&quot;) %>'></asp:HyperLink>

I pass &quot;username&quot; as the parameter, how would be able to pass 2 parameters? And also would I be to count the amount of parameters being accepted on in UserDetails.aspx?(Like passing parameters to Main() in a program).

Cheers,
Kev.
 
It looks like you are using a server side hyperlink. If you want to pass things across just set the NavigateURL to somthing like this

hyperlink.NavigateUrl = &quot;UserDetails.aspx?username=&quot; & data & &quot;&password=&quot; & data

The end result will be a URL like so
UserDetails.aspx?username=joe&password=bubba
 
you can also do this:

DataBinder.Eval(Container.DataItem, &quot;username,val1,val2&quot;, &quot;UserDetails.aspx?id={0},{1},{2}&quot;)

As for counting, you can always evaluate request.querystring.count, but depending on what asp.net wants to send along with it (viewstate, etc...), it might not be accurate -- or rather, it might not be what you'd expect it to be.
penny1.gif
penny1.gif
 
Cheers Link, that ws pretty much what I was looking for.
 
Link,

I get an error when I pu something like this in:

DataBinder.Eval(Container.DataItem, &quot;username,location&quot;, &quot;UserDetails.aspx?id={0},{1},{2}&quot;)

Telling me that it doesn't recognise &quot;username,location&quot; or something along those lines. Any ideas?

And Zarcom, I am doing this inside a Datalist so I will have to use this notation inside of the HTML.
 
Kev, I'm trying to find my examples of how to do this.

This can be done, as I saw it done several times during the conference I attended. I just can't seem to put my hands on the exact syntax at the moment. It's something very very close to what I've posted, though (might tweak and test).

As soon as I find it, I will post here. Hopefully today... but I have to work, too. ;-)

paul
penny1.gif
penny1.gif
 
Kev,

I'm sorry it took me so long to get back to you on this one. I have good news and bad news. Unless I'm going completely crazy, I KNOW I saw the type of thing done that I tried to recreate up there. However, I've been unable to (1)put my hands on the example and (2)locate someone that can tell me how it was done.

On to the good news. I received this reply from an ASP.NET trainer, which I will just post verbatim here:

--------------------------------------------------------
Well the way DataBinder.Eval works it's looking for a single property of
the object (the first parameter). So I don't think you can get multiple
fields into DataBinder.Eval. However, there's nothing to prevent you
from stacking multiple DataBinder.Eval's together or combing
DataBinder.Eval with Container.DataItem expressions. For example, the
following works on my test page:

<%#
DataBinder.Eval(Container.DataItem,&quot;price&quot;,&quot;UserDetails.aspx?id={0}&quot;)
%>,

<%#Container.DataItem(&quot;title_id&quot;)%>,<%#Container.DataItem(&quot;title&quot;)%>

Of course, given the type of expression we are using here, we can avoid
using DataBinder.Eval alltogether (which is a good thing since it always
evaluates expressions at runtime using Reflection). In fact, the above
can be replaced with to reveal the same results:

UserDetails.aspx?id=<%#Container.DataItem(&quot;price&quot;)%>,

<%#Container.DataItem(&quot;title_id&quot;)%>,<%#Container.DataItem(&quot;title&quot;)%>
----------------------------------------------------------
Credit for this info goes to Paul Litwin.

I'm still looking, though, and when (if?) I find it, I will post back to this thread. In the meantime, I hope this helps.

:)
paul
penny1.gif
penny1.gif
 
Thanks to Link9, this thread gave me the idea to fix the above problem using SQL. I just made a field in the dataset called &quot;TheHyperlink&quot;, and built it up in the query:

select book_id, book_title, author_address, book_price, 'edit_entry.aspx?Id=' convert(varchar(6), book_id) + '&Price=' + book_price as TheHyperlink from books

Set the DataNavigateURLField = &quot;TheHyperlink&quot;
Using this method is probably a lot cleaner codewise, and can give you unlimited parameter options.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top