DataGrid

R

Raja Balaji R

hi

i have table emp which contains field eno, ename, esal.

i displaying it in a datagrid

eno column is hyperlinkcolumn
ename, esal are normal bound column

i want that eno hyperlinkcolumn href value to be in
form "sample.aspx?eno=1&ename=rock", 1 is the value of
eno column(hyper column) value and rock is the ename column
(bound column).

how to give URL, URL field, URL format string values in
datagrid columns property dialog.

thanks in advance
 
M

Mike Moore [MSFT]

Hi Raja,

You need to use the ItemDataBound event.

I created a query using the Pubs database as follows:
"SELECT au_id, au_lname, au_fname FROM authors"

I then added a datagrid with a hyperlink column plus autogenerate columns.

I then use string manipulation to create the hyperlink as follows.

Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then

CType(e.Item.Cells(0).Controls(0), HyperLink).NavigateUrl =
"http://" & e.Item.DataItem("au_id") & "?lname=" &
e.Item.DataItem("au_lname") & "&fname=" & e.Item.DataItem("au_fname")

CType(e.Item.Cells(0).Controls(0), HyperLink).Text = "http://"
& e.Item.DataItem("au_id") & "?lname=" & e.Item.DataItem("au_lname") &
"&fname=" & e.Item.DataItem("au_fname")

End If

End Sub

----
I hope this helps.

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer’s security.

This posting is provided "AS IS", with no warranties, and confers no rights.


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

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top