Solved

Ho to create a hyperlink dynamically in Gridview

Posted on 2013-10-28
4
429 Views
Last Modified: 2013-11-05
Hello guys,

I have a situation that my grid view can contain the child items. And if it contains the child item i want to some how create a link button or a hyper link and open a seperate window to see the child items?
I think i need to replace the label with the hyperlink field in row data bound of the grid view but stuck on actually how to do that?

many thanks
0
Comment
Question by:shah36
[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
  • 3
4 Comments
 
LVL 3

Expert Comment

by:netmaster1355
ID: 39605297
maybe it helps you:
http://www.codeproject.com/Questions/143724/

There are two ways. You can create HyperLinkField or add a Hyperlink in <asp:templatefield >
 
Ex.
<Columns>
                <asp:HyperLinkField DataTextField="LeadID" DataNavigateUrlFields="LeadID" DataNavigateUrlFormatString="LeadInformation.aspx?LeadID={0}" Text="Lead ID" />
                <asp:BoundField DataField="DateTime" HeaderText="Date Updated" />
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Bind("LeadID") + Request.QueryString("type") %>'
                            Text=""></asp:HyperLink>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
>

Open in new window


Method 2
----------------------

You can add a TemplateField in the GridView control using the Edit Column
option from the context menu when you click on the smart tag.
 
1. Add a TemplateField in the Selected Fields list.
 
2. Now Right click on the Grid and select Edit Templates. Now drop the
Hyperlink control in the ItemTemplate of the Grid.
 
3. Now bind the NavigateURL and Text property of the Hyperlink to the
hyperlink column field in the table using Data Bindings.
 
4. Now if you click on the hyperlink, it will take you to that page.


also VIDEO
------------------
http://www.youtube.com/watch?v=dIKN9vbbUIw&feature=youtu.be
0
 

Author Comment

by:shah36
ID: 39605306
Thanks for your answer. But actually my hyperlink depends on a condition that is let's say if recored type = A then create hyperlink else display a label or text box
0
 

Accepted Solution

by:
shah36 earned 0 total points
ID: 39605407
Actually i have done this by template field and row data databound. I am sure there must be a better way of doing this?

 <ItemTemplate>
                                <asp:Label ID="lblMeasure" runat="server" Text='<%# Bind("MeasDef") %>'></asp:Label>
                                <asp:HyperLink ID="hprMeasure" runat="server" Visible ="false" Target="_blank"></asp:HyperLink>
                            </ItemTemplate>

Then in row data bound

 if (e.Row.RowType == DataControlRowType.DataRow)
            {
                  Label lblMeasure = (Label)e.Row.FindControl("lblMeasure");
                HyperLink hprMeasure = (HyperLink)e.Row.FindControl("hprMeasure");

If (isChild) //ischild is method and returns true or false
{
    lblMeasure.Visible = false;
                   hprMeasure.Visible = true ;
                   hprMeasure.Text = lblMeasure.Text;
                   hprMeasure.NavigateUrl ="~/KPIs/test.aspx?OEValID=" +txtOEValID.Text .ToString();
}
 else
               {
                   lblMeasure.Visible = true;
                   hprMeasure.Visible = false;
}
}
0
 

Author Closing Comment

by:shah36
ID: 39623750
Well it is working fine for me and i have waited for two three days that if some one woule give any better solution
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

688 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