473,388 Members | 1,256 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

How to show data as hyperlink in ASP.Net datagrid

hi everyone

i want to ask u people could anyone help me how can i display the data in the datagrid column as hyperlink so that when i click on dat cell that will redirect me to the specified page.......

hope i have well explained my question thanx in advance.....



bye
Dec 29 '06 #1
4 15593
Hyperlink Column - Use the HyperLinkColumn column type in a DataGrid control to create a hyperlink for each row in the DataGrid. Set the Text property to specify the caption text for the hyperlink. Unless you are pulling hyperlinks from your datasource, each hyperlink will be the same for each row.


Source : http://dotnetjunkies.com/Article/F25D02EA-7763-4C96-AA27-260388F848D9.dcik
Dec 29 '06 #2
hi everyone

i want to ask u people could anyone help me how can i display the data in the datagrid column as hyperlink so that when i click on dat cell that will redirect me to the specified page.......

hope i have well explained my question thanx in advance.....



bye
I had to do something like this once before, and I used the viewstate in order to do it. We had a datagrid that would output unknown columns based on user queries. Here is the solution I found:

Expand|Select|Wrap|Line Numbers
  1.     protected void grdResults_RowDataBound(object sender, GridViewRowEventArgs e)
  2.     {
  3.         // Go through the header row and if the column header is
  4.         //  the flagged header I'm looking for, mark the viewstate
  5.         if (e.Row.RowType.ToString().Equals("Header"))
  6.         {
  7.             for (int i = 0; i < e.Row.Cells.Count; i++)
  8.             {
  9.                 DataControlFieldCell tc = (DataControlFieldCell)e.Row.Cells[i];
  10.                 if (tc.ContainingField.HeaderText.Equals(flaggedHeader))
  11.                 {
  12.                     ViewState.Add("hypercolumn", i);
  13.                 }
  14.             }
  15.         }
  16.         // Go through the rest of the rows in the datagrid, if there is a viewstate
  17.         // marked, set the hyperlink
  18.         else
  19.         {
  20.             for (int i = 0; i < e.Row.Cells.Count; i++)
  21.             {
  22.                 if (ViewState["hypercolumn"] != null)
  23.                 {
  24.                     if (i == (int)ViewState["hypercolumn"])
  25.                     {
  26.                         HyperLink h = new HyperLink();
  27.                         h.Text = e.Row.Cells[i].Text;
  28.                         h.NavigateUrl = myURL;
  29.  
  30.                         // Setting Target to _blank causes it to open a new
  31.                         // window when clicking on the hyperlink.  Not setting
  32.                         // this property means that clicking on the hyperlink will
  33.                         // redirect the current window
  34.                         h.Target = "_blank";
  35.                         e.Row.Cells[i].Controls.Add(h);
  36.                     }
  37.                 }
  38.             }
  39.         }
  40.     }
If the columns are defined in the code behind, then all you need is to make the column hyperlink, set the NavigateUrl and the Target.
Also, if you end up messing with the viewstate the way I did, remember to reset the viewstate.
Dec 29 '06 #3
Hi...
Expand|Select|Wrap|Line Numbers
  1. <asp:datagrid id="applications" runat="server" Width="392px" Height="149px" BorderColor="#006A00" HorizontalAlign="Left" BorderStyle="Double" PageSize="5" AutoGenerateColumns="False">
  2.  
  3. <Columns>
  4.                         <asp:HyperLinkColumn DataNavigateUrlField="application_id" DataNavigateUrlFormatString="applicationform.aspx?id={0}" DataTextField="application_id" HeaderText="APPLICATION_ID"></asp:HyperLinkColumn>
  5.  
  6. <asp:BoundColumn DataField="EMP_CODE" HeaderText="EMPCODE" ReadOnly="True"></asp:BoundColumn>
  7.                         <asp:BoundColumn DataField="leave_type" ReadOnly="True" HeaderText="LEAVE_TYPE"></asp:BoundColumn>
  8.  
  9. </columns>
  10. </asp:datagrid>
Hope this helps You..

Happy Coding





hi everyone

i want to ask u people could anyone help me how can i display the data in the datagrid column as hyperlink so that when i click on dat cell that will redirect me to the specified page.......

hope i have well explained my question thanx in advance.....



bye
Dec 30 '06 #4
Thanks you ashima515.
Good luck and happy
May 3 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: cksj | last post by:
I have a link on my web app that opens a pop-up window. In the pop-up window, the user can search for policy information. The result is displayed on a datagrid. The datagrid has 1 hyperlink column...
4
by: | last post by:
I have a datagrid with a template column that has a hyperlink and a label. The hyperlink text is bound to Title from my dataset and the label text is bound to Author in the dataset. The grid...
1
by: Machelle Chandler | last post by:
All, I'm trying to populate a datagrid with a data adapter that uses a stored procedure with a parameter. I get the below error when I run my code (as seen below). Any hints? If I delete...
1
by: Matthew Louden | last post by:
The following prints a table of datagrid: Dim dt As DataTable = ds.Tables(0) dgEmployeeInfo.DataSource = dt dgEmployeeInfo.DataBind() I want to add a hyperlink in each ID field, so that the...
3
by: Raja | last post by:
I have a datagrid, it has dropdown box as a column and i have one more column that has hyperlink. The NavigateURL for the hyperlink is to open a new window with a query stirng parameter as the...
5
by: tshad | last post by:
Is there a way to carry data that I have already read from the datagrid from page to page? I am looking at my Datagrid that I page through and when the user says get the next page, I have to go...
3
by: TPhelps | last post by:
I have a sample of an unbound (autogeneratecolumns is true) sortable/pagable datagrid that works. I want to change one of the columns to a hyperlink. The examples I find use a bound column. I...
1
by: mitramay | last post by:
I am creating a dynamic datagrid. The controls in some of the template columns will have to be generated based on the data contained in them (i.e. the data for that respective DataField column)....
0
by: mingr9 | last post by:
hi, my first post here... i am doing a database system that need VB6 to access the Database. The database is make in MS Access 2003. There is Hyperlink column in one of the table.... i able...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.