| re: Disab;e selection of dropdownlist items (in a GridView)
You can write the clientId of the GridView to the page during the page
load. As an old skool zealot, I keep all my JScript in a separate file,
so I use a helper function that looks like this:
Note, this will only work in browsers which support the HTML DOM - IE
5+, FireFox or Opera will all work happily. If you want this to work in
older browsers, you're on your own.
Also note, this is a fairly MacGuyver-esque kludge and it's probably
not hard to break it with unusual situations, but it's worked so far :)
I keep meaning to write a handler so I can generate JS files on the
fly, but deadlines have prevented me so far.
<code>
var __elementRefs__ = [];
function getSingleElement(id, tagName, refresh)
{
if(undefined === __elementRefs__[id] || refresh)
{
var re = eval("/"+id+"$/");
var a =
null==tagName?document.body.childNodes:document.ge tElementsByTagName(tagName);
var i = a.length;
while(i-->0)
{
if(re.test(a[i].id))
{
__elementRefs__[id] = a[i];
return a[i];
}
}
return __elementRefs__[id] = null;
}
else
return __elementRefs__[id];
}
</code>
Pass it an id and a tagname and it will return the first match in your
page. It caches previously selected elements to avoid repeating the
whole eval/regex match. The tagname is optional, but speeds the process
up.
So in your case, do:
var gridView = getSingleElement("ProjectListGridView", "table"); |