Binding two fields in the DataNavigateUrlFormatString

G

genc_ymeri

Hi,
I would like to bind the hyperlink column but I don't see how to.

I tried somethink like this but instead of showing ID nummbers it shows
"ID=ID"

Any tip is very much appreciated.

Genc


PS:
Code I tested with

aHLCol.DataTextField = "RR_ID"

aHLCol.DataNavigateUrlField = "FILEPATH"

aHLCol.DataNavigateUrlFormatString = "{0}?ID=" &
resultTable.Column("ID").ToString ()

aHLCol.HeaderText = "http:/cnn.com/{0}"

dgSearchResults.Columns.Add(aHLCol)

dgSearchResults.DataSource = resultTable

dgSearchResults.DataBind()
 
C

CaffieneRush

I'm guessing you want the url's ID parameter to be set to the ID column
of first row in the results table.

aHLCol.DataNavigateUrlFormatString="{0}?ID=" &
resultTable.Rows(0)("ID").ToString()
 
G

genc_ymeri

Not really, my table has two columns formName and RecordID so I would like
something like the {0} does but for another datafield. eg. below


DataNavigateUrlFormatString="{0}?ID=" &
resultTable.Columns("ID").ToString() updated to each row.

so the DataNavigateUrlFormatString would be




form=f1&ID=1
form=f2&ID=2
form=f3&ID=3

where fn & n values are the values of the formName & its ID in the n-row.

Genc.
 
C

CaffieneRush

Hmm, that's a tough one. I believe you can handle the ItemBound event
and modify the url within the hyperlinkcolumn. Never had the occasion
to do what you need but I think the code below would illustrate my
point.

aHLCol.DataNavigateUrlFormatString = "{0}?ID=<RecordID>" 'the real
data would be substituted with the real data during ItemBound.

AddHandler dgSearchResults.ItemBound, AddressOf DGItemBound

dgSearchResults.Columns.Add(aHLCol)
dgSearchResults.DataSource = resultTable
dgSearchResults.DataBind()

'Assume aHLCol is the 1st column in the DataGrid
Sub DGItemBound(sender As Object, e As DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then

'Replace <RecordID> in the 1st column with the correct
value from resultTable
e.Item.Cells(0).Text =
e.Item.Cell(0).Text.Replace("<RecordID>",
resultTable.Rows(e.Item.ItemIndex)("RecordID"))
End If
End Sub

That is another reason I prefer to work with GridView.
Good luck.
 
G

genc_ymeri

aHLCol.DataNavigateUrlFormatString = "{0}?ID= said:
data would be substituted with the real data during ItemBound.

Yes ! you are right....

I assumed MS should provide the means without going extra steps b/c already
it provides half of it, the DataNavigateUrl.

I kept trying something like

DataNavigateUrl = "f1, f2" or {"f1","f2"}

thinking that's the most likely MS had implemeted that (following the
pattern)....... As you showed, I could have manipulated the datagrid in
its events as well I could have manipulated the ds adding another column on
the fly before binding etc..,,,,,

Interesting enough, after google it, I read that my assumed "way" of doing
it, it is implemented in .Net 2.0 (I haven't try it though)

What did as a quick solution is that I added another column in my sql
stamement select '<a href= .......' and resolved everything ...........


Thanks a lot and very much appreciated,
Genc.
 
C

caffienerush

Hi Genc,

Please post the other way of binding multiple parameters to
DataNavigateUrl because I think my idea of replacing the parameter
during ItemBound is a bit of a bodge.

Regards,
Andy
 
P

Patrick.O.Ige

You can do this
<asp:HyperLink runat="server" Text="View"
NavigateUrl='<%# "urpage.aspx?ID=" & _
Container.DataItem("urID") & _
"&showpage=" & Container.DataItem("secondID")
%>' />
Hope that helps
Patrick
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top