Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to convert a data column into a hyperlink column which navigates to a specified page when clicked..navigation pages are different for each cell...here is the code..
ASP.NET
<asp:GridView ID="gvDept" runat="server" AllowSorting="True"
                    AutoGenerateColumns="False" BorderWidth="1px" CellPadding="1" CellSpacing="1" 
                    PagerSettings-Visible="true"                   
                     Width="100%" >
                    <HeaderStyle CssClass="whr-GridHead" VerticalAlign="Top" HorizontalAlign="Center"/>
                    <RowStyle CssClass="whr-Grid" />
                    <AlternatingRowStyle CssClass="whr-GridAlt" />
                   <Columns>
                                          <asp:BoundField DataField="DeptCode"  HeaderText="Department Code" ItemStyle-HorizontalAlign="Center"
                                                ItemStyle-Width="5%" Visible="true">
                                                <ItemStyle HorizontalAlign="Center" Width="5%" />
                                            </asp:BoundField>
                                             <asp:BoundField DataField="DeptDescription"  HeaderText="Department Name" ItemStyle-HorizontalAlign="Center"
                                                ItemStyle-Width="5%" Visible="true">
                                                <ItemStyle HorizontalAlign="Center" Width="5%" />
                                            </asp:BoundField>
                                            
                                        </Columns>
                </asp:GridView>

Thanks in advance...
Posted

Look at the following part of code, maybe it will help:
C#
<columns>
<asp:hyperlinkfield xmlns:asp="#unknown">
    DataNavigateUrlFields="UserId"
    DataNavigateUrlFormatString="userProfile.aspx?ID={0}"
    DataTextField="UserName"
    HeaderText="User Name"
    SortExpression="UserName" />
</asp:hyperlinkfield></columns>


Also, you can find a full discussion here: http://forums.asp.net/t/1086879.aspx[^]
 
Share this answer
 
Comments
Ashit Mehra 12-Mar-13 6:51am    
can u give me a solution specific to my code??
I went to the link also but cud not get it.I am new to this and have no idea how to use DataNavigateUrlFields & DataNavigateUrlFormatString...
Mihai02 12-Mar-13 7:04am    
Declare in <asp:GridView> tags the DataKeyNames and give it the id column of your table. Then follow each line and I think you will manage to implement your solution. I think this can fit your code:

<asp:GridView ID="gvDept" runat="server" AllowSorting="True"
AutoGenerateColumns="False" BorderWidth="1px" CellPadding="1" CellSpacing="1"
PagerSettings-Visible="true" DataKeyNames="INSERT ID COLUMN HERE"
Width="100%" >
<HeaderStyle CssClass="whr-GridHead" VerticalAlign="Top" HorizontalAlign="Center"/>
<rowstyle cssclass="whr-Grid">
<alternatingrowstyle cssclass="whr-GridAlt">
<columns>
<asp:HyperLinkField DataNavigateUrlFields="ID_COLUMN_HERE (PROBABLY DEPARTMENT ID)"
DataNavigateUrlFormatString="www.google.com"
DataTextField="DeptCode"
HeaderText="Department code" />


Ashit Mehra 12-Mar-13 7:16am    
This works perfectly!thanks a lot!
but i want to navigate the values in the column on click to some specified pages..how do i do that??
Thanks again for the help :)
Mihai02 12-Mar-13 7:19am    
You just set the value you want DataNavigateUrlFormatString to your URL. If you want to navigate to a details page let's say for a specific department you set your page (see my first example and my link) and add the "?ID={0}" option. The {0} is a place holder and it will be changed with the value from the DataNavigateUrlFields attribute.
Ashit Mehra 12-Mar-13 7:59am    
done!!
thanks a lot for the help!!
go through following link study it try to implement in ur code...
Practical Guide for Creating HyperLinkField in GridView in ASP.NET[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900