Answered by:
Hyperlink in DataRow and Gridview

Question
-
Hello,
Below code does not work. Hope someone can help.
Thanking you in advance for your help.
cheers,
~goutam
Public dtMainDataTable As New Data.DataTable Public dcMainDataTable As New Data.DataColumn Public drMainDataTable As Data.DataRow Public Sub InitDataTable() ' Initialize dcMainDataTable = New Data.DataColumn dcMainDataTable.DataType = System.Type.GetType("System.Web.UI.WebControls.HyperLink") dcMainDataTable.ColumnName = "Search Results" Me.dtMainDataTable.Columns.Add(dcMainDataTable) End Sub Public Sub RetrieveData() Dim hlResHyperLink As New HyperLink Dim sText As String = "Some_Text" Dim sNavigationUrl As String = "~/Some_Url.aspx" ' Assigning values hlResHyperLink = New HyperLink hlResHyperLink.Text = sText hlResHyperLink.NavigateUrl = sNavigationUrl drMainDataTable = dtMainDataTable.NewRow drMainDataTable.Table.Rows.Add(hlResHyperLink) dtMainDataTable.Rows.Add(drMainDataTable) End Sub Public Sub MainModule() call InitDataTable() call RetrieveData() ' Assign to gridview If Not dtMainDataTable Is Nothing Then Me.gvAdvSearch.DataSource = dtMainDataTable Me.gvAdvSearch.DataBind() End If End Sub
- Moved by Mike Feng Friday, February 22, 2013 2:15 AM
Thursday, February 21, 2013 7:21 AM
Answers
-
What do you mean with "does a not work":
- Is it a DataTableProblem
- Does it not show
Be aware that in the first case probably the Dataset forum is at least also a good choise to ask your question.
http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataset/threads
If the DataBind does not work (the page does is not shown) then
http://forums.Asp.Net 'Also Microsoft
Success
CorThursday, February 21, 2013 12:04 PM -
Hi Goutam,
Welcome to the MSDN Forum.
Please try this issue on asp.net forum: http://forums.asp.net/
Thank you for your understanding and support.
Best regards,
Mike Feng
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Marked as answer by Just Karl Friday, November 22, 2013 7:49 PM
Friday, February 22, 2013 9:25 AM
All replies
-
The by you used datatype is not a base type datatype.
See the remarks on this page.
http://msdn.microsoft.com/en-us/library/system.data.datacolumn.datatype(v=vs.110).aspx
You can try String instead of that.
Success
CorThursday, February 21, 2013 7:51 AM -
Plz don't put type like a control, u should put something like int, double as a REAL NUMBER in DataTable, this is a contain that can contain values only.
U can use TemplateFields+<a href=……> to bind with hyperlink value in ur DataTable's specific column.
Thursday, February 21, 2013 7:54 AM -
Hello,
Thank you for trying to help.
I changed :
dcMainDataTable.DataType = System.Type.GetType("System.Web.UI.WebControls.HyperLink")
to
dcMainDataTable.DataType = System.Type.GetType("System.String")
But, still it does not work.
cheers,
~goutam
Thursday, February 21, 2013 8:25 AM -
Hi again,
Have u used TemplateFields?
What's ur aspx?
Thursday, February 21, 2013 9:25 AM -
Hi,
It already is a template field. Please check :
<li> <div class="time">Results</div> <p> </p> <p> <asp:GridView ID="gvAdvSearch" runat="server" Height="552px" Width="768px" EnableSortingAndPagingCallbacks="True" EmptyDataText="No data found"> <AlternatingRowStyle BackColor="WhiteSmoke" /> <Columns> <asp:TemplateField> <EditItemTemplate> <asp:HyperLink ID="HyperLink6" runat="server">HyperLink</asp:HyperLink> </EditItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </p> </li>
Please guide how should I proceed from here.
cheers,
~goutam
Thursday, February 21, 2013 10:28 AM -
Try to use ItemTemplate:
<asp:TemplateField> <ItemTemplate> <a href='<%#Eval("BoundField")%>'>Click Me</a> </ItemTemplate> </asp:TemplateField>
Thursday, February 21, 2013 11:42 AM -
What do you mean with "does a not work":
- Is it a DataTableProblem
- Does it not show
Be aware that in the first case probably the Dataset forum is at least also a good choise to ask your question.
http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataset/threads
If the DataBind does not work (the page does is not shown) then
http://forums.Asp.Net 'Also Microsoft
Success
CorThursday, February 21, 2013 12:04 PM -
Hi,
I guess it has a combination of a few problems. That's why I posted in this group.
It has both DataTableProblem (adding hyperlink to DataRow) and it does not show on screen.
Let me try with ItemTemplate and get back to you soon.
cheers,
~goutamFriday, February 22, 2013 2:48 AM -
Hi Goutam,
Welcome to the MSDN Forum.
Please try this issue on asp.net forum: http://forums.asp.net/
Thank you for your understanding and support.
Best regards,
Mike Feng
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Marked as answer by Just Karl Friday, November 22, 2013 7:49 PM
Friday, February 22, 2013 9:25 AM