Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to establish which checkbox in DataGrid clicked - by Row ?

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
We have a checkBox in a Template column in an ASP.NET DataGrid.
This checkbox is used to multi-select rows in the grid (for instance - a selection of returned records from a lookup).
How can we establish the most recently clicked row in the DataGrid - i.e. the last row in the grid that we selected the checkbox against ?
Any suggestions would be appreciated.
Thanks in advance,
Steve
 
Could you load all of the selected checkboxes into a DataTable/Collection/Array as presumably they will have all been given an incrementing ID then you just need to find the highest ID (you may need to split the generated ID but you should be able to just look at incremental number)

Does that make sense?

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
That makes sense - but perhaps my use of the word 'last' wasn't. ;)
Sorry.
By 'last' I meant most recent - so for instance rows 3, 4, 8, 10 and 12 might be selected - and then the user selects row 6.
It would be 6 as the last row ...
Any further thoughts ?
Steve
 
Ah I see - I took "last" to mean "highest".

Hmmm...the only possible solutions I can think of are:

1) Have AutoPostBack set to True for each checkbox and update a variable each time a checkbox is selected

2) In javascript add the ID of the checkbox to an array and pass that array back to the server when you need to find this "last" entry (the last entry will be the most upperbound entry in the javascript array)

Hope this helps.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
A slight twist ca8msm's suggestion would be to put an onclick event (client side) on the checkboxes, passing its unique id to a client side function, where you would simply append that value to a string variable (probably comma separated for subsequent clicks).

That string var would start each request as an empty string, so you would always have only what was clicked on that request in the variable.

You could simply assign the string variable to a hidden form variable, which would be posted back when the form was submitted.
Code:
<script language=javascript>
var m_Clicked = '';
function AppendString(p_Value)
{
  m_Clicked += p_Value + ',';
  document.forms[formName].elements['Clicked'].value = m_Clicked;
}
</script>
<input type=hidden name=Clicked />
So each click on the checkbox calls AppendString and you can simply Request.Form["Clicked"] to get the values on PostBack.

-paul

penny.gif
penny.gif

The answer to getting answered -- faq855-2992
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top