Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

datagrid making all boundcolumn a hyperlink

Posted on 2004-03-23
8
Medium Priority
?
324 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
6 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Screencast - Getting to Know the Pipeline

782 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