GridView selection question

  • Thread starter Thread starter CK
  • Start date Start date
C

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
 
You need to add code similar to the following in the GridView RowDataBound
event:
string js = Page.ClientScript.GetPostBackEventReference(YourGridView,
"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
 
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 said:
You need to add code similar to the following in the GridView RowDataBound
event:
string js = Page.ClientScript.GetPostBackEventReference(YourGridView,
"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 said:
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
 
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(GridView1, "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 said:
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 said:
You need to add code similar to the following in the GridView RowDataBound
event:
string js = Page.ClientScript.GetPostBackEventReference(YourGridView,
"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 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top