?
Solved

Ho to create a hyperlink dynamically in Gridview

Posted on 2013-10-28
4
Medium Priority
?
431 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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
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…
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

771 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