Solved

How make a label clickable or select which is inside a gridview

Posted on 2008-10-14
3
175 Views
Last Modified: 2013-12-17
Hi Experts,
i have my search results being displayed a grid view like below.

Item            Title                 Price        Size
A1001       Black Shoes    $15             5

what i want to do now is make the Item field clickable so when some one clicks on it (A1001) it will to that particular item page. Can some one please tell me how to do this. i can post my code i have so far
Thanks I really Appreciate it
0
Comment
Question by:niceoneishere
3 Comments
 
LVL 8

Accepted Solution

by:
tiagosalgado earned 500 total points
ID: 22714172
1. Create gridview RowDataBound event
2. Create gridview SelectedIndexChanged event
Then add the following code on code-behind

************** RowDataBound EVENT **********

if (e.Row.RowType == DataControlRowType.DataRow)

            {

                e.Row.Cells[0].Attributes.Add("onmouseover","this.style.cursor='hand'; this.style.backgroundcolor='#000000'");

                e.Row.Cells[0].Attributes.Add("onclick", Page.ClientScript.GetPostBackClientHyperlink(your_gridview_name, "Select$" + e.Row.RowIndex.ToString()));

            }
 
 

********************* SelectedIndexChanged EVENT *******************

get your cell value from selected row with your_gridview_name.SelectedRow.Cells[0].Text;

and then do what you whant when user click
 

Add this code too to override your page Render method
 

protected override void Render(System.Web.UI.HtmlTextWriter writer)

        {

            for (int i = 0; i < your_gridview_name.Rows.Count; i++)

            {

                Page.ClientScript.RegisterForEventValidation(new System.Web.UI.PostBackOptions(your_gridview_name, "Select$" + i.ToString()));

            }

            // Do the standard rendering stuff

            base.Render(writer);

        }

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Linq Help 1 34
Need help on C# Linq query on object 6 51
Anyway to make "All" the default in the dropdown? 6 34
SSL https .net web site force redirect 3 31
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

932 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

13 Experts available now in Live!

Get 1:1 Help Now