473,388 Members | 1,376 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

GridView selection question

CK
Good morning all,
I had a quick question, I would like to make a row in a gridview selectable.
Currently there is a asp:CommandField as one of the colums. This selects the
current row when pressed. My desire is to eliminate this column and just
make the row selectable. Any ideas?
Thanks In Advance,
~CK
Aug 7 '06 #1
3 2452
You need to add code similar to the following in the GridView RowDataBound
event:
string js = Page.ClientScript.GetPostBackEventReference(YourGr idView,
"Select${0}");
js = String.Format(js, e.Row.RowIndex);
e.Row.Attributes["onclick"] = js;
e.Row.Style.Add("cursor", "hand");

where (e) is GridViewRowEventArgs

hope it helps

Regards
--
Muhammad Mosa
Software Engineer & Solution Developer
MCT/MCSD.NET
MCTS: .Net 2.0 Web Applications
MCTS: .Net 2.0 Windows Applications
"CK" wrote:
Good morning all,
I had a quick question, I would like to make a row in a gridview selectable.
Currently there is a asp:CommandField as one of the colums. This selects the
current row when pressed. My desire is to eliminate this column and just
make the row selectable. Any ideas?
Thanks In Advance,
~CK
Aug 7 '06 #2
CK
I get some kind of postback callback eventvalidation error. It doesn't quite
work. Seems like I am close though. Any ideas? The error says to use
Page.ClientScript.RegisterForEventValidation

but I must be passing the wrongs args.

Thanks,

~CK

"Muhammad Mosa" <Mu**********@discussions.microsoft.comwrote in message
news:7B**********************************@microsof t.com...
You need to add code similar to the following in the GridView RowDataBound
event:
string js = Page.ClientScript.GetPostBackEventReference(YourGr idView,
"Select${0}");
js = String.Format(js, e.Row.RowIndex);
e.Row.Attributes["onclick"] = js;
e.Row.Style.Add("cursor", "hand");

where (e) is GridViewRowEventArgs

hope it helps

Regards
--
Muhammad Mosa
Software Engineer & Solution Developer
MCT/MCSD.NET
MCTS: .Net 2.0 Web Applications
MCTS: .Net 2.0 Windows Applications
"CK" wrote:
>Good morning all,
I had a quick question, I would like to make a row in a gridview
selectable.
Currently there is a asp:CommandField as one of the colums. This selects
the
current row when pressed. My desire is to eliminate this column and just
make the row selectable. Any ideas?
Thanks In Advance,
~CK

Aug 7 '06 #3
Well I'm not sure what is the mistake you may made, but I've built a sample
may be similar to yours, I've created a RowDataBound Event Handler for my
GridView like the following
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//string js = "javascript:__doPostBack('GridView1','Select${0}') ";
string js =
Page.ClientScript.GetPostBackEventReference(GridVi ew1, "Select${0}");
js = String.Format(js, e.Row.RowIndex);
e.Row.Attributes["onclick"] = js;
e.Row.Style.Add("cursor", "hand");
}
}

Another way to solve the same problem but I prefer the above, Anyway test
it, you may prefer to use it:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string js = "javascript:__doPostBack('GridView1','Select${0}') ";
js = String.Format(js, e.Row.RowIndex);
e.Row.Attributes["onclick"] = js;
e.Row.Style.Add("cursor", "hand");
}
}

I hope this could resolve your issue
--
Muhammad Mosa
Software Engineer & Solution Developer
MCT/MCSD.NET
MCTS: .Net 2.0 Web Applications
MCTS: .Net 2.0 Windows Applications
"CK" wrote:
I get some kind of postback callback eventvalidation error. It doesn't quite
work. Seems like I am close though. Any ideas? The error says to use
Page.ClientScript.RegisterForEventValidation

but I must be passing the wrongs args.

Thanks,

~CK

"Muhammad Mosa" <Mu**********@discussions.microsoft.comwrote in message
news:7B**********************************@microsof t.com...
You need to add code similar to the following in the GridView RowDataBound
event:
string js = Page.ClientScript.GetPostBackEventReference(YourGr idView,
"Select${0}");
js = String.Format(js, e.Row.RowIndex);
e.Row.Attributes["onclick"] = js;
e.Row.Style.Add("cursor", "hand");

where (e) is GridViewRowEventArgs

hope it helps

Regards
--
Muhammad Mosa
Software Engineer & Solution Developer
MCT/MCSD.NET
MCTS: .Net 2.0 Web Applications
MCTS: .Net 2.0 Windows Applications
"CK" wrote:
Good morning all,
I had a quick question, I would like to make a row in a gridview
selectable.
Currently there is a asp:CommandField as one of the colums. This selects
the
current row when pressed. My desire is to eliminate this column and just
make the row selectable. Any ideas?
Thanks In Advance,
~CK


Aug 8 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: tarscher | last post by:
Hi all, I have a gridview populated with data coming from a dataset (created via the wizard). The data shown in the gridview is dependent on the the choice of a control (dropdown with...
0
by: sharonrao123 | last post by:
hello all, I have a parent gridview company and in this one a nested gridview people, Is it possible to allow the user to select one row or multiple rows from the people gridview using a check box...
0
geo039
by: geo039 | last post by:
I have a usercontrol with textboxes. Most of which refer to a gridview on selection. A user clicks a looking glass and a gridview appears to select items (like a dropdown). The page loads with...
0
by: Rasika WIJAYARATNE | last post by:
Hi everyone, I have two grid-views and I am trying to populate the data on gv2 based on the selection in gv1. However when a row is selected in gv1, it doesn't populate the gv2 with data. I have...
13
by: SAL | last post by:
Hello, I'm trying to include a popup in the ItemTemplate of a gridview row. The ItemTemplate for the field contains a textbox and when the user clicks in the textbox I want a popup panel to show...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.