Solved

datagrid making all boundcolumn a hyperlink

Posted on 2004-03-23
8
311 Views
Last Modified: 2012-08-13
How to  make every whole line in a datagrid a hyperlink? I have seen ppl coding this way, but i can't figure out how to do it. pls help.

thnx
0
Comment
Question by:biao81
  • 4
  • 2
8 Comments
 
LVL 5

Expert Comment

by:fahimnxb
Comment Utility
Dear biao81
USE TEMPLATE COLUMNS

Exampe 1
-----------
<asp:TemplateColumn>
    <ItemTemplate>
        <asp:HyperLink runat="server" Text="" NavigateUrl=""
ID="LinkBtn"></asp:HyperLink>
    </ItemTemplate>
</asp:TemplateColumn>

[CodeBehind]
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType ==
ListItemType.Item)
{
    HyperLink lnk = (HyperLink)e.Item.Cells[5].FindControl("LinkBtn");
    lnk.NavigateUrl = "xxxxxxx";
    lnk.Target = "_blank";
    lnk.Text = "Open";
}

Example 2
------------
<asp:datagrid>
<columns>
<asp:templatecolumn>
<headertemplate>Question</headertemplate>
<itemtemplate>
<a href='mainIndex.aspx?Id=<%#
DataBinder.Eval(Container.DataItem, "quest_id")
%>&Other=<%#
DataBinder.Eval(Container.DataItem, "quest_other")
%>'><%#
DataBinder.Eval(Container.DataItem, "quest_name")
%></a>
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>

Ask if there is any confusion.
FaHiM
0
 

Author Comment

by:biao81
Comment Utility
no. i don't want to use itemtemplate, i want to use boundcolumn itself, as itemtemplate cannot be sorted
0
 
LVL 5

Expert Comment

by:fahimnxb
Comment Utility
If you want to use columns in bound mode, use hyperlink columns.
For a short detail of data grid column types visit
http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=332

HyperLink column surely solve your problem.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 5

Expert Comment

by:fahimnxb
Comment Utility
An example is

<asp:datagrid>
<columns>
<asp:HyperLinkColumn DataTextField="quest_name" HeaderText="Question" DataNavigateUrlField="quest_id" datanavigateurlformatstring="mainIndex.aspx?Id={0}>"/>
</Columns>
</asp:datagrid>

The problem with hyperlink column is you cannot send more than two paramters in QueryString, for this you have to use Template Column.
0
 

Author Comment

by:biao81
Comment Utility
<asp:HyperLinkColumn DataTextField="quest_name" HeaderText="Question" DataNavigateUrlField="quest_id" datanavigateurlformatstring="mainIndex.aspx?Id={0}>"/>

where does this {0} come from? and more than two parameters in querystring? so if i put 3, will it be an runtime error or the third parameter will not be captured?
0
 
LVL 5

Accepted Solution

by:
fahimnxb earned 50 total points
Comment Utility
Dear Biao81,

The {0} is the DataNavigateUrlField="quest_id", and I already mentioned...........

The problem with HYPERLINK COLUMN is you cannot send more than two paramters in QueryString, for this you have to use Template Column.

Try it with 3 you will find out what it gonna behave. :)

Ask if still there are confusion.
FaHiM
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now