Multiple URL Fields in a datagrid

G

Guest

Hi there,

I have a datagrid that is bound to a datasource. The grid has a hyperlink
column and I want to generate the URL using the URL Field and URL Format
String fields in the Property Builder.

The problem I'm running into is trying to generate the URL with more than
one URL Field entry. I need to have more than field but I can't figure out
how to add more than one field in the URL Field textbox. Is it possible?

I would want the URL Format String to look something like...

MyURL.aspx?field_1={0}&field_2={1}

Any help would be greatly appreciated.

Carlo.
 
J

Joe Fallon

You can't do it using a normal bound column.
You need a template column.

Then in the dg_ItemDataBound event you create an instance of the hyperlink
and find it using FindControl and then set its properties.
In this case the dg is bound to a collection and the index of the collection
equals the index of the grid. So you can always identify whcih row you are
on.

=======================================================================
<asp:TemplateColumn SortExpression="myColumn" HeaderText="My Header">
<ItemTemplate>
<asp:Hyperlink id="hylMyColumn"
runat="server"></asp:Hyperlink>&nbsp;
</ItemTemplate>
</asp:TemplateColumn>
=======================================================================

Private Sub dg_ItemDataBound(ByVal sender As Object, ByVal e As
DataGridItemEventArgs) Handles dg.ItemDataBound
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then

'need to take paging into account!
Dim mIndex As Integer = CType(sender, DataGrid).PageSize *
CType(sender, DataGrid).CurrentPageIndex + e.Item.ItemIndex

'set hyperlinks values:
'Note: in the HTML the &nbsp; is required because the grid cells will
change shape w/o it when there is no data.

Dim ohylMyColumn As HyperLink =
CType(e.Item.FindControl("hylMyColumn"), HyperLink)

ohylMyColumn.NavigateUrl =
"javascript:LeftSideWin('ViewSomePage.aspx?Key=" & mCollection(mIndex).key &
_
"&KeyType=" & mCollection(mIndex).keytype & "','MyScreen');"

oHylInvNumber.Text = mCollection(mIndex).MyDescription

End If
End Sub
=======================================================================
 

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,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top