Hello there!
I've got a datagrid I've dynamically created from a sproc. Note I autogenerate the columns from a dataset (this may be a bad thing). I want to either:
1) Add a hyperlink column in front of all other columns. The data in the 1st column of the datagrid will form part of the url for the new hyperlink column. (Am I making myself clear???)
-- or --
2) Change the first column of the datagrid to be a hyperlink column using it's own data as the url.
So in either case the new hyperlink column will have a url that reads (as an example): job.aspx?id=343 (343 coming from the 1st column of the dataset).
I've tried a few techniques but I'm stuck. I've tried adding a column and then using the grid's itemdatabound event.
Existing code is below, I've left in some of my awful attempts but commented these out.
If you check the Lookup.RetrieveIE line, all that does is return a dataset. Of course behind the scenes it dynamically builds the select statement to query the database to put the results into a dataset.
Please keep in mind that I need to have paging and sorting on the datagrid. Sorting, of which, I haven't been able to get to work properly. If you could include the code for that I would appreciate it!
Thankyou in advance
Adrian
--------------------------
----------
----------
----------
----------
----------
----------
----------
----------
----------
----------
-------
Dim dr As DataSet
Private Sub CreateGrid()
Dim Lookup As New cLookup
dr = Lookup.RetrieveIE(Request(
"JobID"))
' some formatting of the datagrid
Me.dgIEOutput.BorderWidth = Unit.Pixel(2)
dgIEOutput.CellPadding = 2
dgIEOutput.GridLines = GridLines.Both
dgIEOutput.BorderColor = Color.Black
dgIEOutput.ShowHeader = True
Me.dgIEOutput.AllowPaging = True
Me.dgIEOutput.PagerStyle.M
ode = PagerMode.NumericPages
Me.dgIEOutput.AllowSorting
= True
'Me.dgIEOutput.Columns.Add
(column)
Dim dv As DataView = New DataView(dr.Tables(0))
' dv.Sort = "Name"
' the following is some poor attempts to add a column at the front
'dr.Tables(0).Columns.Add(
"Try")
'Dim datagridcol = New HyperLinkColumn
'datagridcol.HeaderText = "Add as Group"
'datagridcol.DataNavigateU
rlFormatSt
ring = "<a href='Job.aspx'>do it now</a>"
'datagridcol.text = "<a href='JobGroup.aspx'>do it now</a>"
'datagridcol.SortExpressio
n = dr.GetName(iCol).ToString(
) & " DESC"
'dr.Tables(0).Columns.Add(
New DataColumn("IntegerValue",
GetType(Integer)))
'dr.Tables(0).Columns.Add(
New DataColumn("StringValue", GetType(String)))
'Dim hc1 As New HyperLinkColumn
'hc1.DataTextField = "StringValue"
'hc1.DataTextFormatString = "Show details for {0}"
'hc1.DataNavigateUrlField = "IntegerValue"
'hc1.DataNavigateUrlFormat
String = "details.aspx?ID={0}"
'hc1.HeaderText = "Show me more"
'dgIEOutput.Columns.AddAt(
0, datagridcol)
'dgIEOutput.AutoGenerateCo
lumns = True
BindData()
'Dim i As Integer
'For i = 0 To dr.Tables(0).Rows.Count - 1
' dr.Tables(0).Rows(i).Item(
0) = "sgdf"
' ' ' datagridcol.DataNavigateUr
lFormatStr
ing = "JobGroup.aspx"
'Next
end sub
Private Sub BindData()
Me.dgIEOutput.DataSource = dr
Me.dgIEOutput.DataBind()
End Sub
'''''''''''' Here is the code I was using for the ItemDataBound event:
Private Sub dgIEOutput_ItemDataBound(B
yVal sender As Object, ByVal e As System.Web.UI.WebControls.
DataGridIt
emEventArg
s) Handles dgIEOutput.ItemDataBound
'Dim hypcol As HyperLinkColumn
'hypcol = dgIEOutput.Columns(1)
'hypcol.DataNavigateUrlFor
matString = "JobGroup.aspx"
End Sub