Solved

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

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

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
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.…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
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…

708 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

16 Experts available now in Live!

Get 1:1 Help Now