Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-02-05
2
Medium Priority
?
535 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
[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
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 1500 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

Independent Software Vendors: 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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

704 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