Solved

datagrid making all boundcolumn a hyperlink

Posted on 2004-03-23
8
314 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

840 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