Solved

Ho to create a hyperlink dynamically in Gridview

Posted on 2013-10-28
4
424 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
abstract class C# 1 35
Adding items to a C# list incrementally 5 58
pressing download button in c# 7 34
C# XML Get Values 4 33
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

735 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