HyperLink

  • Thread starter Giuseppe Vitalone
  • Start date
G

Giuseppe Vitalone

Hi! I've a Hyperlink and I want to give him a dinamic url... how can I do?
In another point of my application I used

<asp:HyperLink runat="server" NavigateUrl='<%
#GetLinkUrl(DataBinder.Eval(Container.DataItem, "item")) %>'/>

In the code behnid file:

protected string GetLinkUrl(object item)
{
...
return "something";
}

and it works very well. Here, I need to call a GetLinkUrl like method but
without arguments. In the code behind I need to examine a DataGrid and to
return a string.
Thanks all
 
R

Robert Koritnik

Do it on the ItemDataBound event. Give your Hyperlink an ID and user
FindCOntrol on the item and cast it to Hyperlink and set NavigateUrl...

In the same item you will have complete item to the bound data of the
datagrid.
 
G

GV

The HyperLink isn't into the datagrid... I have to set the NavigateUrl
looking to the values in a datagrid, but the hyperlink is one and outside
tha grid. Sorry for my English...
 
R

Robert Koritnik

What do you want it to be set to? If it's datagrid item idependent, what
would you like to do? This way I might help you. Maybe you should do that in
DataBinding? I don't know. Explain a bit how would you like to obtain the
NavigateUrl...
 
G

GV

I'll try... I put into a panel some DataGrid created at run-time. The
DataGrid has a not visible column which contains numbers separated by commas
(example: "1234,56"), and a column with checkboxes. Then I have a HyperLink.
When the user selects some check boxes and clic over the link, I must
prepare a navigate url; the url starts with "./page.aspx?" and must continue
with "Cod=" + first number + "&Cod=" + second number + ... etc.
I tried to recreate data grids after post back and, with a button, to do
that, but there are several strange problems about maintaining viewstate.
I hope you'll understand my English :D
Thanks, bye
 
R

Robert Koritnik

Ok. Two ways to acomplish this:
1. Do it on the client
2. Do it on the server

AD.1 create a javascript array that you will put in your selections when you
click them (use OnClick event in Javascript on clientside) When you click
the link, you can use that array to make a compound string of
Cod=...&Cod=...

AD.2
Just create an event delegate for checkbox change event and attach it to
every checkbox. On the postback the event will fire before link click and do
a simmilar thing as in the javascript, except that you could use ArrayList
(dynamic sizing) and use that variable in the click event of the hyperlink
control. Change events ALWAYS fire BEFORE action events (like button, link
etc. clicks...).

Hopw this helps.
 

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,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top