Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hyperlinks in datagrid based on a condition

Status
Not open for further replies.

tman24m

Programmer
May 21, 2001
93
US
Hey all,
I'd like to have a field displayed as a hyperlink in one of my columns, but only if one of the other fields = 51. Here is what I've got.

Private Sub dgMGLUNSfill()
Dim strSQL As String
strSQL = "select GJID, GJDESC, GJAMT " & _
"from MSTLIB.MGLUNS " & _
"where GJACCT = '" & cmbAccounts.SelectedItem.Value & "' "

Dim dr As OleDbDataReader
dr = GetDataReader(strSQL)

dgMGLUNS.DataSource = dr

'set up columns for grid
dgMGLUNS.AutoGenerateColumns = False

Dim urlCol As HyperLinkColumn = New HyperLinkColumn()
urlCol.DataTextField = "GJID"
urlCol.DataNavigateUrlField = "GJID"
urlCol.HeaderText = "I.D."

Dim ammtCol As BoundColumn = New BoundColumn()
ammtCol.DataField = "GJAMT"
ammtCol.HeaderText = "Ammount"
ammtCol.DataFormatString = "{0:c}"

Dim descCol As BoundColumn = New BoundColumn()
descCol.DataField = "GJDESC"
descCol.HeaderText = "Description"

dgMGLUNS.Columns.Add(urlCol)
dgMGLUNS.Columns.Add(ammtCol)
dgMGLUNS.Columns.Add(descCol)
'---------end column setup----------



dgMGLUNS.DataBind()
End Sub


Basically what I would like is to have the field only be a hyperlink if GJID = 51

Any Suggestions?
 
I am taking this solution from an FAQ that I wrote faq855-2613

Change the FormatColumn function to accept two parameters of obj type.
In the function check to see if the incoming value is 51. If it is simply create and return a string containing an html anchor with the value that you want from the second paramter. If not then return a normal string.

When you call the function as described in the FAQ simply send both columns needed in as parameters.

That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Thanks for the post. However, In your FAQ, you say to use an asp:textbox in the datagrid. I'm unclear on how to do this. Please Explain.

Thanks
trent
 
Sweet! I figured it out. I added a table to a template column and that worked. Thanks for the help!
 
glad to help

That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top