v-jetan
2/27/2004 3:12:00 AM
Hi Deanna,
Sorry for letting you wait for so long time.
Actually, when a html element is disabled, any style you applied to it will
not take effect, it will always become gray. This is by the design of the
Html behavior.
I think you want to disable the "select" html tag just to prevent the
dropdownlist to be select. And you just want the dropdownlist to be
readonly(Not selectable, I think this is what you said "not editable").
But, unfortunately, there is no "readonly" attribute for "select" html tag.
After doing a lot of research, the only workaround I can think of is using
other "can readonly" html tag to replace the "select" tag. You can get this
done through client javascript. For example, you can replace the "select"
html tag with readonly textbox(<input type=text>) or other suitable tag.
I wrote a sample below, in the sample, I use a "mutiple" one-size "select"
html tag(Which can not be drop down, so hehave like readonly) to replace
normal "select" tag:
<SELECT id="dropdownlist" style="Z-INDEX: 101; LEFT: 152px; WIDTH: 248px;
POSITION: absolute; TOP: 72px; HEIGHT: 136px"
name="dropdownlist">
<OPTION selected>asdfasd1</OPTION>
<OPTION>asdfasd2</OPTION>
<OPTION>asdfasd3</OPTION>
<OPTION>asdfasd4</OPTION>
<OPTION>asdfasd5</OPTION>
<OPTION>asdfasd6</OPTION>
</SELECT>
<script language="javascript">
function hidedropdownlist()
{
var so=document.createElement("select");
var op=document.createElement("option");
so.multiple=true;
so.size=1;
so.options.add(op);
so.options(0).text
=document.all("dropdownlist").item(document.all("dropdownlist").selectedInde
x).text;
so.style.position="absolute";
so.style.left= document.all("dropdownlist").style.left;
so.style.width=document.all("dropdownlist").style.width;
so.style.top=document.all("dropdownlist").style.top;
document.all("dropdownlist").style.visibility="hidden";
document.body.appendChild(so);
}
</script>
In the javascript code, I set the new-created "select" object's position
and size the same as original one. Then I hide the original
"dropdownlist"(select object).
Note:
1). You must apply "so.style.position="absolute"" to make the position is
absolute based.
2). You must apply "so.multiple=true" and "so.size=1" to make the
dropdownlist to be only one line(So can not be select and to be readonly)
You can invoke hidedropdownlist() at any client javascript event as you
like.
Btw: if you want to do this thing at server side(Such as in DropDownList
web control), you may use Page.RegisterClientScriptBlock to dynamicly
generate this code.
==========================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Have a nice day!!
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.