?
Solved

Dynamically add a hyperlink column to the front of a dynamically created datagrid

Posted on 2003-11-23
9
Medium Priority
?
1,614 Views
Last Modified: 2012-05-04
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.Mode = 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.DataNavigateUrlFormatString = "<a href='Job.aspx'>do it now</a>"
        'datagridcol.text = "<a href='JobGroup.aspx'>do it now</a>"
        'datagridcol.SortExpression = 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.DataNavigateUrlFormatString = "details.aspx?ID={0}"
        'hc1.HeaderText = "Show me more"

        'dgIEOutput.Columns.AddAt(0, datagridcol)
        'dgIEOutput.AutoGenerateColumns = 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.DataNavigateUrlFormatString = "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(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgIEOutput.ItemDataBound
        'Dim hypcol As HyperLinkColumn

        'hypcol = dgIEOutput.Columns(1)
        'hypcol.DataNavigateUrlFormatString = "JobGroup.aspx"
    End Sub
0
Comment
Question by:adrianroyce
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 2

Expert Comment

by:adomsg
ID: 9808180
The best is u dont autogenerate the columns..
Below teaches u hw to add hyperlink and the url

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskaddinghyperlinkcolumnstodatagridwebcontrol.asp
0
 
LVL 2

Expert Comment

by:adomsg
ID: 9808196
For sorting:
Set the allowSorting properties to TRUE in the datagrid.

Below is the code to add in VB.NET

Private Sub datagrid_SortCommand(ByVal sender As System.Object, ByVal e As DataGridSortCommandEventArgs) Handles datagrid.SortCommand

   session("searchOnly") = select * from table ORDER BY " + e.SortExpression
conn.open()
Dim myAdapter As New OleDbDataAdapter(Session("searchOnly"), Conn)
            myAdapter.Fill(datagrid)
            datagrid.DataSource = dstResult
            datagrid.DataBind()
            Conn.Close()
end sub
0
 

Author Comment

by:adrianroyce
ID: 9808259
adomsg
I put autogenerate columns on as there is an unknown quantity of columns retrieved from the datasource.
I cannot predict which columns the user will choose from the 50 or so columns.

Is there a better way than the way I have done it so far?

Adrian
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 2

Assisted Solution

by:adomsg
adomsg earned 750 total points
ID: 9808890
The sorting still can be used, but the hyperlink thing i am not very sure.
0
 
LVL 12

Accepted Solution

by:
roverm earned 750 total points
ID: 9808985
Why don't you use a TemplateColumn? See this example:
http://aspnet.4guysfromrolla.com/articles/040502-1.aspx

It includes the TemplateColumn and the Sorting issue.

D'Mzz!
RoverM
0
 

Author Comment

by:adrianroyce
ID: 9815808
I was hoping that someone could provide much more of a solution than the ones already provided.  It even seems some of you haven't read my entire request.  I am offering 500 points, if that's not enough, please let me know, I have more to spare.
Thanks
Adrian
0
 

Author Comment

by:adrianroyce
ID: 9815867
ok, I worked it out (great sigh of relief).
And yes I used a Template column, however I didn't realize that I could define a template column before hand with the Property Builder and then Bind the data and asp.net appends the columns to the end of the template column.
That's very cool.
Thankyou Roverm and adomsg.  I'll split the points between you guys.  I can use other ideas you've given me too.
0
 
LVL 12

Expert Comment

by:roverm
ID: 9816346
Thanks! Glad we could help.
0
 
LVL 2

Expert Comment

by:adomsg
ID: 9821948
Thanks...
0

Featured Post

Python: Series & Data Frames With Pandas

Learn the basics of Python’s pandas library of series & data frames and how we can use these tools for data manipulation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question