Solved

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

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

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…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

634 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