Solved

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

Posted on 2014-02-05
2
528 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 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
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 …
Suggested Courses

710 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