Solved

asp.net getting selected gridview hyperlink row's text to label

Posted on 2014-02-05
2
522 Views
Last Modified: 2014-02-06
while having gridview with hyperlinks

 foreach (GridViewRow gr in gv01.Rows)
        {
            HyperLink hp = new HyperLink();
            hp.Text = gr.Cells[0].Text;
            hp.NavigateUrl = "~/Default.aspx?name=" + hp.Text;
            gr.Cells[0].Controls.Add(hp);
        }

trying to get

 protected void gv01_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        int selectedIndex = e.NewSelectedIndex;
        lblservermappath.Text = gv01.Rows[selectedIndex].Cells[0].Text;
    }

to display in label,
not quite worked
0
Comment
Question by:doramail05
2 Comments
 
LVL 13

Expert Comment

by:Jesus Rodriguez
ID: 39839268
Try This

int selectedIndex = e.NewSelectedIndex;
HyperLink MyHyperlink=gv01.Rows(selectedIndex).FindControl("HyperLink1") as hyperlink;
MyLabel.text = MyHyperlink.Text;
0
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 39840346
You would have to add the Id to use the findcontrol:

            HyperLink hp = new HyperLink();
            hp.Text = gr.Cells[0].Text;
            hp.NavigateUrl = "~/Default.aspx?name=" + hp.Text;
            hp.ID = "hlDefault"          
            gr.Cells[0].Controls.Add(hp);
       
Then you could find it by:
   HyperLink MyHyperlink=gv01.Rows(selectedIndex).FindControl("hlDefault") as hyperlink;

Or if you wanted to use your method you would have to go into the controls:
 lblservermappath.Text = gv01.Rows[selectedIndex].Cells[0].Controls[0].Text;
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 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