Solved

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

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display

726 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