datagrids, property builder, link columns

  • Thread starter Thread starter Lauchlan M
  • Start date Start date
L

Lauchlan M

Hi

I have a datagrid.

In the property builder I set a hyperlink column.

I need to make the hyperlink take two url parameters, eg go to a page
mypage.aspx?FirstVar={0}&SecondVar={1}

I tried setting the URLField to

FieldID1; FieldID2

or

FieldID1, FieldID2

but it gives me the error

Exception Details: System.Web.HttpException: A field or property with the
name 'FieldID1; FieldID2' was not found on the selected datasource.

So, it looks for _one_ field with the two names joined together. How do I
set it up (syntax etc) to recognise two fields in the URLField entry?

Failing that, how do I add a column to my grid with a hyperlink to a page
with two url parameters, as above?

Thanks!

Lauchlan M
 
Hi LauchLan,

Inorder to retrieve 2 parameters in the url link, u need to have an
additional bound column with 'FirstVar&SecondVar' as FinalVar and make
it visible=false.

Create a template column with hyperlink to a javascript function calling
as this.value, for e.g.:
<a href="#" runat=server id="A1" onclick="fxEdit(this.value)" value='<%#
DataBinder.Eval(Container.DataItem, "finalvar")%>'
NAME="finalvar">Edit</a>

function fxEdit(xitem){
var items = xitem.split("&")
if (items.length>0){
var FirstVar = items[0];
var SecondVar = items[1];
}
window.location.href="webform.aspx?FirstVar=" + FirstVar +
"&SecondVar=" + SecondVar;

}

Hope this will help. I did the same thing and its working fine. Let me
know if you still can't get it.

Cheers :)
Shaf
(e-mail address removed)
 
Hi Shafi,

I'm not really following properly . . .

In my SQL in the select command, I have changed it to something like "select
someotherfields, sd.SessionID + '&HospitalID=' + sd.HospitalID as KeyVar
FROM SessionData sd"

So that added in the composite key there, and I modified the URLfield to be
KeyVal.

This however gets me an error

<<
Query execution failed:
Could not convert variant of type (String) into type (Double) [no error
code]
ThreadID: 2352

---------------------------------------------------------
]
NexusDB.ADOProvider.NxDatasetProxy.nxCheck(Int32 aCode)
NexusDB.ADOProvider.NxDatasetProxy.Execute(String sCmd,
NxDatasetProxyResultSet& resultset, Boolean readBlobs)
So it seems to want to insist that the key field is an integer which stuffs
up this approach!

I can't see how to do it the way you suggested either, my hyperlink column
SQL is currently

<asp:HyperLinkColumn Text="Details" DataNavigateUrlField="SessionID;
HospitalID"
DataNavigateUrlFormatString="SessionDetails.aspx?SessionDataID={0}&amp;Hospi
talID={1}" HeaderText="Details"></asp:HyperLinkColumn>

Do you mean to modify this one to be something like

<a href="#" runat=server id="A1" onclick="fxEdit(this.value)" value='<%#
DataBinder.Eval(Container.DataItem, "finalvar")%>' NAME="finalvar">Edit</a>

or to create a completely new secondary link column?

Thanks!

Lauchlan M
Inorder to retrieve 2 parameters in the url link, u need to have an
additional bound column with 'FirstVar&SecondVar' as FinalVar and make
it visible=false.

Create a template column with hyperlink to a javascript function calling
as this.value, for e.g.:
<a href="#" runat=server id="A1" onclick="fxEdit(this.value)" value='<%#
DataBinder.Eval(Container.DataItem, "finalvar")%>'
NAME="finalvar">Edit</a>

function fxEdit(xitem){
var items = xitem.split("&")
if (items.length>0){
var FirstVar = items[0];
var SecondVar = items[1];
}
window.location.href="webform.aspx?FirstVar=" + FirstVar +
"&SecondVar=" + SecondVar;

}

Hope this will help. I did the same thing and its working fine. Let me
know if you still can't get it.
 
Hi Lauchlan,

First of all u need to combined 2 vars into 1 in a sql statement. if any
var is integer or date/time u need to convert using convert function to
varchar. for e.g. select id,
convert(varchar(10),firstvar)+'&'+convert(varchar(10),secondvar) as
finalvar from tablename

This will solve ur ADO/SQL problem.

In Datagrid, create the template column not the hyperlink column, like
this:
<asp:TemplateColumn HeaderText="Edit"> <HeaderTemplate>
Edit </HeaderTemplate> <ItemTemplate> <a href="#"
runat=server id="Button1" onclick="fxEdit(this.value)" value='<%#
DataBinder.Eval(Container.DataItem, "finalvar")%>' NAME="finalvar">
Edit</a> </ItemTemplate> </asp:TemplateColumn>

{0} only you'll be able to access as a datagrid datafield and you cannot
use {1} or {2} like that.

Pls try this. if you still can't get it, u need to look into SQL/ASP.NET
manuals.

Cheers :)
Shaf
(e-mail address removed)
 
Back
Top