Solved

Ho to create a hyperlink dynamically in Gridview

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now