?
Solved

datagrid making all boundcolumn a hyperlink

Posted on 2004-03-23
8
Medium Priority
?
321 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Cloud Training Guides

FREE GUIDES: In-depth and hand-crafted Linux, AWS, OpenStack, DevOps, Azure, and Cloud training guides created by Linux Academy instructors and the community.

 
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 200 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

719 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