Solved

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

Posted on 2008-10-14
3
179 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
[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
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

690 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