Print Page | Close Window

Unable to pass values to a Hyperlink Colu

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=12066
Printed Date: 29 March 2026 at 3:11am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Unable to pass values to a Hyperlink Colu
Posted By: vshriniwasan
Subject: Unable to pass values to a Hyperlink Colu
Date Posted: 07 October 2004 at 7:11pm

Hey guys, I am using BoundColumn and HyperlinkColumns to create a datagrid.

I have two bound Columns that provides me two values.

I am trying to pass those two values to the Hyperlinkcolumn to pass it as a querystring into a model window.

Code:

 For i = 0 To myDataSet.Tables(0).Columns.Count - 1

                 Dim dgColumn As New BoundColumn

                 Select Case myDataSet.Tables(0).Columns(i).ColumnName

                     Case "id"
                         dgColumn.HeaderText = "Id"
                         dgColumn.DataField = myDataSet.Tables(0).Columns(i).ColumnName
                         dgWorkflow.Columns.Add(dgColumn)

                     Case "name"
                         dgColumn.HeaderText = "Name"
                         dgColumn.DataField = myDataSet.Tables(0).Columns(i).ColumnName
                         dgWorkflow.Columns.Add(dgColumn)

                 End Select
Next

Dim dgHColumn As New HyperlinkColumn
dgHColumn.Text = "View"
dgHColumn.NavigateUrl = "Javascript: alert('value1/value2')

How can i have each value in in row to be passed into the link.

Thanks,

Shrini




Replies:
Posted By: Mart
Date Posted: 08 October 2004 at 11:26am
Could you explain what you want to do a bit more? I don't know what you want


Posted By: vshriniwasan
Date Posted: 08 October 2004 at 2:49pm

To simply put, I want a third column in the datagrid that willt ake the values of the ID and Name and pass as a querystring.

Any help will be appreciated.

Thanks,
Shrini



Posted By: Mart
Date Posted: 08 October 2004 at 3:08pm
ahh, ok. Convert it to a template column in property builder, then go into HTML view and change the markup inside the third template column to something like:


<a href='mypage.aspx?ID=<%# Databinder.Eval(Container.DataItem, "ID") %>&Name=<%# Databinder.Eval(Container.DataItem, "Name") %>'>View details</a>



Posted By: vshriniwasan
Date Posted: 08 October 2004 at 8:53pm

I understand that Mart.

My problem is I have to write it programatically, and I am having extreme problems. I do have HTML view option on what I am writing on. Everything is straight code behind. Is it possible you can show me a simple example on how to do that code behind.

Thanks again,

Shrini



Posted By: Mart
Date Posted: 09 October 2004 at 3:57am
Sure, in your code behind just put:


Public Function GetLink(ByVal ID As Integer, ByVal Name As String) As String
Return String.Format("mypage.aspx?ID={0}&Name={1}", ID, Name)
End Function


then in design view have this:


<a href='<%# GetLink(Databinder.Eval(Container.DataItem, "ID"), Databinder.Eval(Container.DataItem, "Name")) %>'>View details</a>



Posted By: vshriniwasan
Date Posted: 09 October 2004 at 1:46pm

I appologize not explaining it right the first time. I should be shot.

I understand using the function.

My thing is, I am doing everything code behind. I simply don't have an optioin use the HTML View to add do the following.

<asp:TemplateColumn>
     <ItemTemplate>
         <%# DataBinder.Eval(Container.DataItem, "id") %>
         <%# DataBinder.Eval(Container.DataItem, "name") %>
     </ItemTemplate>
</asp:TemplateColumn>

I have to actually write the whole thing in the code behind and populate it in to the datagrid. Again no access to HTML view for me to insert ASP controls. All Controls are beng generated from code behind.

I need to do the following and what I marked in red is giving me an error saying dataitem is not a member of "System.ComponentModel.Container". If I use a # sign then it says expression expected.

Dim myCol as New TemplateColumn
myCol.ItemTemplate = GetLink(DataBinder.Eval(Container.DataItem, "id"),DataBinder.Eval(Container.DataItem, "name"))

Public Function GetLink(ByVal ID As Integer, ByVal Name As String) As String
     Return String.Format("mypage.aspx?ID={0}&Name={1}", ID, Name)
End Function

This gets solved, my biggest headch is over. Becasue of this problem I had to change my code to old ASP style and loop through each record, formating it into a table and then assigning it into a label. Lets not forget finding a rope next to me and hanging myself doing it in that manner rather an simply doing it with a dg.

What I understand is I have to Use ITemplate to get this working if I am going to do this programmatically...

I can't find any proper VB reference on ITemplate to get it going. Not even a simple example...



Posted By: Mart
Date Posted: 09 October 2004 at 2:28pm
Usually any type beginning with an I is an interface, I don't know off hand but I'm sure ITemplate is an interface. So you need to type the following:


Public Class MyTemplate
Implements ITemplate

End Class


After you press <Enter> after the implements line VS should insert some Properties, Subs etc... You need to fill these, then you can use MyCol.ItemTemplate = MyTemplate. I will write you an example if I have time


Posted By: vshriniwasan
Date Posted: 10 October 2004 at 8:55pm

I have been trying to find some where in the web where people might have an simple working example. Can't find it any where.

Does any one have any ideas or know how to work it and can tell me what I should do with a templace column programmatically.

Thanks,

Shrini




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net