473,387 Members | 1,705 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,387 software developers and data experts.

How to add Hyperlink in gridview column in windows application developed in c#

I am developing windows application using visual studio 2008 and c#.

I have a GRIDVIEW, but I am not sure how to make a specific column of gridview as hyperlink.
For Example: First column of my grid view is Item ID and if user clicks any of the value in this column a new form should open.

Below is the code of my GIRDVIEW

Expand|Select|Wrap|Line Numbers
  1. DataSet ds;
  2.         DataSet ds3;
  3.  
  4.         public void FillGridView(int LotID)
  5.         {
  6.             clsPurchase obj = new clsPurchase();
  7.             ds = obj.GetData("Select a.LotItemID as 'Item ID',c.CompanyName as Client,a.Description,convert(varchar, a.LotItemAddedDate, 3) as 'Date',a.Weight,a.Rate,a.Amount from dbo.Lot_Items a left join Client c on a.ClientID = c.ClientID where LotID = " + LotID + "");
  8.             ds3 = new DataSet();
  9.             DataTable dt3 = ds3.Tables.Add();
  10.             dt3.Columns.Add("Item ID", typeof(string));
  11.             dt3.Columns.Add("Client", typeof(string));
  12.             dt3.Columns.Add("Description", typeof(string));
  13.             dt3.Columns.Add("Date", typeof(string));
  14.             dt3.Columns.Add("Weight", typeof(double));
  15.             dt3.Columns.Add("Rate", typeof(double));
  16.             dt3.Columns.Add("Amount", typeof(double));
  17.  
  18.  
  19.             DataGridViewCellStyle style = new DataGridViewCellStyle();
  20.             style.Font = new Font(dataGridView1.Font, FontStyle.Bold);
  21.  
  22.             int i = 0;
  23.             double WeightTotal = 0.00;
  24.             double RateTotal = 0.00;
  25.             double AmountTotal = 0.00;
  26.             if (ds.Tables[0].Rows.Count > 0)
  27.             {
  28.                 foreach (DataRow row in ds.Tables[0].Rows)
  29.                 {
  30.                     dt3.Rows.Add(ds.Tables[0].Rows[i]["Item ID"].ToString(), ds.Tables[0].Rows[i]["Client"].ToString(), ds.Tables[0].Rows[i]["Description"].ToString(), ds.Tables[0].Rows[i]["Date"].ToString(), ds.Tables[0].Rows[i]["Weight"].ToString(), ds.Tables[0].Rows[i]["Rate"].ToString(), ds.Tables[0].Rows[i]["Amount"].ToString());
  31.                     WeightTotal = WeightTotal + Convert.ToDouble(ds.Tables[0].Rows[i]["Weight"].ToString());
  32.                     RateTotal = RateTotal + Convert.ToDouble(ds.Tables[0].Rows[i]["Rate"].ToString());
  33.                     AmountTotal = AmountTotal + Convert.ToDouble(ds.Tables[0].Rows[i]["Amount"].ToString());
  34.                     i = i + 1;
  35.                 }
  36.                 dt3.Rows.Add("Total", "", "", "", WeightTotal.ToString(), RateTotal.ToString(), AmountTotal.ToString());
  37.                 //dataGridView1.Rows[0].DefaultCellStyle = style;    
  38.                 dataGridView1.DataSource = ds3.Tables[0];
  39.                 dataGridView1.Rows[i].DefaultCellStyle = style;
  40.                 dataGridView1.Rows[i].DefaultCellStyle.Font = new Font("Tahoma", 15);
  41.                 //dataGridView1.Rows[i].DefaultCellStyle.ForeColor = Color.Blue;
  42.                 dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.LightGray;
  43.                 this.dataGridView1.DefaultCellStyle.Font = new Font("Tahoma", 9);
  44.                 this.dataGridView1.ColumnHeadersDefaultCellStyle.Font = new Font("Tahoma", 9);
  45.                 this.dataGridView1.ReadOnly = true;
  46.  
  47.             }
  48.         }
  49.  
  50.  
Thanks in advance.
Mar 26 '13 #1
2 2928
r035198x
13,262 8TB
You should probably have posted this in one of the .NET forums.
You can links using the RowDatabound events http://msdn.microsoft.com/en-us/libr...databound.aspx

But if you want to navigate to other pages within your application then you may want an approach like

i) make the column in your gridview a HyperLinkField.
ii) Set the DataNavigateURLFields to values that you can link to in the new page (most likely the unique identifiers) e.g clientId
iii)Set the DataNavigateUrlFormatString to the new page with the real values substituted in e.g yourNewPage.aspx?clientId=someValue

Alternatively you can read about how others do the whole master detail data presentation solution e.g http://mattberseth.com/blog/2008/04/..._gridview.html
Mar 26 '13 #2
Rabbit
12,516 Expert Mod 8TB
This thread has been moved to the C# forum.
Mar 26 '13 #3

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

Similar topics

2
by: Sujatha | last post by:
Hi, I have a windows application developed which can run in system tray. I want to set up the executable to run while the OS starts. One way, i can think of doing it is by writing a windows...
3
by: Hans Merkl | last post by:
Hi, I was wondering if it's possible to bind the header text of a GridView column to a method of an object I have. At the moment I am setting the header texts in Page_Load but I was wondering if...
2
by: Filipe Marcelino | last post by:
Hi, I'm an experienced vb .net developer in windows forma. Now I'm trying to develop a windows service and I would like to know if it's possible to raise an event from a windows application...
4
by: archana | last post by:
Hi all, Can any one tell me how to upload file in windows application developed in C#.net. Or can i use method webclient.uploadfile in windows application. Please help me asap. thanks in...
11
by: Doc John | last post by:
I have a Windows application developed in VS.Net 2002 and upgraded to VS2005, and when I try to run it in an 800x600 resolution, it doesn't load completely (plus its memory usage is really high)....
2
by: =?Utf-8?B?SkRSYXZlbg==?= | last post by:
I have searched all over and can not seem to find an effective way to simply copy the contents of a ASP:gridview column to the clipboard based on a button or similar HTML or ASP.NET control. ASP...
4
by: Yin99 | last post by:
I have a Gridview binding to a DataTable source. I'd like to set the column with of the second column. I cannot do this apparently because when AutoGenerateColumns=true, they do not appear in the...
2
by: vanitha05 | last post by:
Hi all, I want the code to bind the array/dataset to gridview in windows application . Its urgent requirement, please give reply soon. Thankyou
1
by: krishnaneeraja | last post by:
Hi, Iam working on windows based application.In that i dont know how to add image in grid view column. I want to add image column in grid view.Image path will be stored in Ms-Access database.I...
0
by: pavanip | last post by:
Hi, I am facing problem with combobox in gridview.I have used combobox in gridview and i am binding data to gridview combobox from database. If i click 2 times on combobox then it is showing the...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.