Solved

datagrid making all boundcolumn a hyperlink

Posted on 2004-03-23
8
313 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
ID: 10664504
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
ID: 10664776
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
ID: 10675001
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 5

Expert Comment

by:fahimnxb
ID: 10675021
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
ID: 10683420
<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
ID: 10684587
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C# Single Form 8 42
execute SQL Stored Procedure 1000 times from vb.net 3 33
How do you do a one to many list in .NET CORE? 2 24
Regular expression help 2 22
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

815 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

8 Experts available now in Live!

Get 1:1 Help Now