Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-10-14
3
Medium Priority
?
183 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 2000 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

610 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