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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hyperlink within grid 1

Status
Not open for further replies.

uncleroydee

Technical User
Nov 28, 2000
79
0
0
US
I'd like to be able to configure one column within a grid to contain hyperlinks to another page within my site. The hyperlink will need to pass data from the row as parameters for the stored procedure on the target page.

I know that this can be done in FrontPage and probably ASP using something like
&quot;<a href=&quot;target.asp?parameter1=cstr(parameter1)¶meter2=cstr(parameter2)&amp;...>&quot; but I'm not sure if the grid wizard will hose the code or vice versa.

Thanks,
 
Roy,

You need to change the entry in the column's 'expression' field in the grid property editor. You can try to build a complicated expression right into the field or you can place a call to a server side function into the field then write your function and return a string.

You can send the Recordset object to the function as a parameter so it has access to the columns of the current row, etc.

Hope this helps
-pete
 
Thanks, Pete.

What I've done till now was write my stored procedure select statement like:
&quot;SELECT '<a href=&quot;url.asp?param1='+datafield1+'¶m2='datafield2...+'</a>'
FROM tbl_data&quot;
So the recordset returned from the database is already written as the url. It works although I'm not sure it's the most efficient way to handle the matter.
I'm going to try your way as well to compare the efficiencies.

Thanks again.

Roy
 
And you may like to know that the grid DTC has the 'anchor' method, which causes the 'current row' to be set.

For a grid column, type

=this.anchor(&quot;Edit&quot;)

[try it and see!][Now change &quot;Edit&quot; to &quot;<IMG SRC...>&quot;!]
If you put in thisPage_onenter some code to update the recordset, then any edits are automatically saved.

You can even place text-box / combo-box DTC controls into a grid. These can show on all rows (but a pain to de-code!) or just on the current row [brilliant!]
 
Thanks for the input, Merlin. I had stumbled on the &quot;=<a href...&quot; and haven't had a need yet for embedding the text box /combo box.

However, I do now have a new question regarding grids. I would like to display a recordset of 2000 +/-, single field, records in a series of grids of 4 columns by 50 rows.
How do I configure the grid to display the first 50 records in the first column, the second fifty records in the second column, third fifty in the third column, etc. as opposed to one column 2000 rows long? (I'm making a BIG assumption that VI will carry the format over to subsequent pages necessary to display the entire recordset.)

Thanks,

Roy

Hope I'm stating the question clearly, I've had a little trouble figuring out how to word it.
 
(multi-column stuff below!)
Putting a complex expression in a grid column can cause a number of problems - particularly when they include single and/or double quotes.

Ink: The your link should be a quoted string...
='<a href=&quot; target=&quot;_blank&quot;>'
(without a semi-colon)

Anything more complex, then create a server-side function (in VBScript or JScript) and refer to it in the grid...

sub gridFormatDateColumn(i_dtValue)
'Rather trivial example
'which may not work.. as the date will be in
'string format by the time it is passed to
'this function

gridFormatDateColumn = FormatDateTime(i_dtValue)
end sub

in the grid:
=gridFormatDateColumn([My_Date_Database_Col])

* notice how the database column(s) are identified using SQUARE BRACKETS [ ].

UncleRoydee: Actually, building the Link in SQL is a great idea and should be much more efficient than this!

MULTIPLE - COLUMNS...

The request to populate a column with the first 50 items, and the second with the next 50 is very tricky when using the DTC grid. Each row of the grid is assumed to come from a SINGLE recordset row. However, not all is lost!

You could fetch all of the data for a complete page into an array and pump it out with your own TR and TD tags (no grid DTC needed). for example:
<%for i = 0 to 49%>
<TR><TD><%=myarray(i)%></TD><TD><%=myarray(i+50)%></TD>..etc..</TR>
<%next%>
(you may wish to convert this to use Response.Write's in a function call)

I have adapted the CheckBox DTC to produce multiple column lists of checkboxs - you can specify the number of columns etc. However, it is not 'paged' like the above would need to be. (Content Management)
 
Hi

I'm reasonably new to Visual Interdev, and although I've found this thread REALLY helpful, I'm afraid I still can't quite master the hyperlink thing.

I need to create a hyperlink which feeds a value through to another page...

I'm trying along the lines of (in one of my column's Field/Expression):
Code:
='<a href=&quot;clientVIEW.asp?VID=<%rst.fields.getvalue(&quot;vehicle_id&quot;)%>&quot;>Edit</a>'

So I have a grid with a number of rows, and for each row, I want an Edit link, which jumps to a uniquely generated page.

The problem I'm having with this is that the ASP code is not being picked up as such... it's taking the <% %> as part of the string I'm trying to include in the URL.

If someone could help me with this I'd be much appreciative...I've been going crazy with it for way too long now! =)

Ta

Annelies
 
The grid expression is enterpreted by JScript - which does not know about <% %>. The recordset-under-the-grid columns can be included simply by placing the column name in square barckets:
='<a href=&quot;clientVIEW.asp?VID=' + [vehicle_id] + '&quot;>Edit</a>'

but it uses string concatenation (the + signs) to make the full text up at runtime.
Sometimes the grid gets confused with single and double quotes within the expression. If this happens, then plonk the expression into a server-side function:

function gridMakeLink (intVehicleID) {
return '<a href=&quot;clientVIEW.asp?VID='
+ intVehicleID
+ '&quot;>Edit</a>'
}
- the funcion can now be quite complex if you wish/need

and in the grid, simply put:

=gridMakeLink([vehicle_id])

Note: this time there is no string concatenation - you want the whole expression evaluated.

If you want to know what happens to the square brackets - look at the underlying grid code (right-mouse the grid and click show runtime text). It displays:

grdSystems.colData[0] = 'grdMakeLink(rsSystems.fields.getValue(\'vehicle_id\'))';

The DTC object converts the square brackets to actual code.

(Content Management)
 
Hi MerlinB,

Can you elaborate on your post about placing DTCs into a grid? I have an Orders grid (showing the following fields: OrderID, CustomerID, and OrderDate) and would like a &quot;Delete Order&quot; DTC button in each row...I want to write an event handler for the button's onclick event, which will not only delete the record corresponding to that row, but also other records with the same OrderID located in another database table (OrderDetails table).

Peggy

P.S. Your input on hyperlinks in this thread was very helpful.
 
Me again. :) I modified MerlinB's Delete hyperlink code to an Update hyperlink that basically updates a recordset (Read his FAQs! They are incredibly helpful and easy to follow!) This hyperlink is used in an editable grid. Is there way a way to do field validation after clicking on the Update hyperlink (and before the recordset is updated!) by using thisPage_onbeforeserverevent(obj, evnt)? If so, what would the 'obj' be since a hyperlink is not a DTC? If not, any alternative methods?

 
There are at least two ways:

1) Get the update hyperlink to execute a client-side function, that performs the validation. If you split the validation out of the on_beforeserverevent and into another function, then you can call it from both places.

2) If you add a button control to the form that would perform the update, and add the server-side onclick event for the button (that could be an empty 'dummy' function - but it is needed for the server round-trip to occur).

Now display the page and do a 'view source', copy the onclick code for the pushbutton. Use this code for the hyperlink - however, if you want to pass additional parameters (like the key of the row to update) then you may need to re-figure this procedure.

The hyperlink will now perform the same action as the pushbutton (which you can now hide).

--------------

The grid has an 'anchor' method, that sets the grid row position. I normally use this to provide a way to both set the current row, and to save any edits - in the thisPage_onenter... thisPage.firstEntered = false...
'Save any changes
rsMyRecordset.update

This ay not appear to be ideal as it always does an update - but you can alter the recordsetDTC code to test each field as it loops around fetching the values from the textboxes etc., and only do a real update if an edit has actually occured.

Not sure where the validation would fit in - perhaps by altering the page tag:
<page onsubmit=&quot;dovalidate();&quot;>
if the dovalidate() returns 'true' then the page submits, else it does not.
Or perhaps the 'anchor' grid function code could be altered.

ttfn (Content Management)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top