Solved

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

Posted on 2008-10-14
3
174 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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

14 Experts available now in Live!

Get 1:1 Help Now