Client side gridview click

G

Guest

I have a gridview with a delete button as follows...

<ItemTemplate>
<asp:ImageButton id="deleteAttachment" OnClientClick='return
confirm("Are you sure you want to delete this Attachment?");'
imageallign="absbottom" commandName="DeleteAttachment" tooltip="Delete this
Attachment" imageurl="images/icons/delete.jpg"
runat="server"></asp:ImageButton>

</ItemTemplate>

Is it possible to highlight the gridview row or change the background color
of the row when its clicked? It will have to be a client side thing
obviously. I guess the OnClientClick property will reference a script
function but how do I know which row was clicked? And what client side code
is required to change the background color of a gridview row?

Or is this possible?

thanks
 
E

Eliyahu Goldin

OnClientClick='return imageButtonClicked(this)';

"this" refers to the html element created by asp.net for the ImageButton. If
you view the page's html source in your browser, you will see exactly what
it is and where it is located. Likely, it is located inside a <td> and the
<td> is inside the <tr>. This is your row. You can navigate to the row with
parentElement property.

Make a css style for a highlighted row. Once you navigate to the row, set
its className property to that style name.
 
G

Guest

Finally figured out a solution for anyone interested...

Use this javascript function, it takes in the id of the gridview button,
then takes the current backcolor of the gridview row (so it can be rest if
you press cancel), and then returns true or false to the call.

<script type="text/javascript" language="javascript">

function ConfirmDelete(ID)
{

var CurrentBackColour = ID.parentElement.parentElement.style.backgroundColor;

ID.parentElement.parentElement.style.backgroundColor='red';

var result = confirm('Are you sure you want to Delete this Line Item?');

if (result == false)
{
ID.parentElement.parentElement.style.backgroundColor=CurrentBackColour;
}

return result;

}

</script>

then in the itemtemplate in your gridview just set the OnClientClick='return
ConfirmDelete(this);' for the button .
 

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

Similar Threads


Members online

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top