Click a row on a datagrid to call SelectedIndexChanged event c#

J

JC

Hi!

I have a datagrid in c#. When you move the mouse over the lines they
highlight. What I really want is for the user to be able to click
anywhere on a line and the 'SelectedIndexChanged' event be called -
enabling me to open another page to edit that selected record.

So, firstly I added a bound Select button, and as expected when I
click the SelectedIndexChanged event gets called, next stage was to
make that button invisible but add the following code to the datagrid
ItemDataBound event...

//This highlights on mouse over - works fine!
e.Item.Attributes.Add("onmouseover",
"this.style.backgroundColor='Silver';this.style.color='white';this.style.cursor='hand'");

//this unhighlights on mouseout - works fine also!
e.Item.Attributes.Add("onmouseout",
"this.style.backgroundColor='white';this.style.color='black';this.style.cursor='hand'");

//this calls the doPostBakc function passing parameters just as the
'select' button does, but it doesnt call the SelectedIndexChanged
event :'(
e.Item.Attributes.Add("onclick","javascript:__doPostBack('" +
"dgAllPosts:" + "_ctl" + 1 + ":_ctl0','')");


Anyways, if anyone can see what I'm doing wrong, or has a better way
to achieve this, I'd love to hear from you.

Thanks chaps

James
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top