472,111 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,111 software developers and data experts.

Multiple URL Fields in a datagrid

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.
Nov 18 '05 #1
1 2556
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
================================================== =====================
--
Joe Fallon


"carlor" <ca****@discussions.microsoft.com> wrote in message
news:61**********************************@microsof t.com...
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.

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Julio Sarmiento | last post: by
3 posts views Thread by D. Shane Fowlkes | last post: by
7 posts views Thread by Dave | last post: by
1 post views Thread by Bob Loveshade | last post: by
8 posts views Thread by Jason L James | last post: by
1 post views Thread by Beginner | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.