how to use javascript to refence control(s) within datagrid?

liunx

Guest
Made myself a datagrid to display info without using the paging feature.

I have few controls inside my <EditItemTemplate>.

I want to use javascript's ".focus" to focus on 1 of my control (a check box) when user click "Edit" on my datalist. So the user won't need to scroll down and search the item that needs to be edit.


thank you

p.s: are there ways we can achieve this without using javascript? I would very much wanted to know.i can help you on this. it gives its own specific name for every row it enters. So to focus on a check box. you have to do something like
document.getElementById("DataGrid1__ctl" + editingrow + "_TXTobj").focus()
Datagrid1 is my data grid and TXTobj is my object and editingrow is row im working at.
but of course you have to know which row is getting editted.
This works i use it alot. And really usefull when doing loops on this so u get to see which row your code is working at. It kicks a$$ :p :D :Dthanks for help drewex,

1) when do u trigger this code? i assume u can't trigger it on page_load because the <edit> template is not even there until you click "edit" or else you will receive javascript error right?

2) where do u put ur javascript code? within aspx page or within code-behind?


thank youYou can do 2 two things (or any other way that i cant think of) In .net code you can try find out which row your working with or this is the way i use in the javascript at the end of the page (so it runs after the datagrid shows up) i run this code
var editingrow = ""
for (x=0; x < document.Form1.tags("input").length; x++)
{
var xname = document.Form1.tags("input")(x).name
if(xname.indexOf("TXTobj") != -1)
{
editingrow = xname.substring(14,15)
}
}

This gave e the input tags name i extract the row info. and i use the editing row all around the code.
Then you can focus right after that line of code. Give it a try.
 
Back
Top