Click here to Skip to main content
15,880,543 members
Articles / Programming Languages / ASP

Online DB Administration

Rate me:
Please Sign up or sign in to vote.
3.88/5 (16 votes)
17 Mar 2003 235.9K   2.5K   58  
Online administration of your database. Create or modify tables, keys, and indexes. Edit or insert data.
<!-- b.dropdown.asp         - copyright (c) 2001-2002 by Bj�rnar Henden http://www.bhenden.org/ -->
<script language=javascript runat=server>
function Out(s) {
	Response.Write(s);
}

function CreateDropdown(name,rs,idfield,displayfield) {
	return new BDropdown(name,rs,idfield,displayfield);
}

function BDropdown(name,rs,idfield,displayfield) {
	this._name = name;
	this._rs = rs;
	this._idfield = idfield;
	this._displayfield = (''+displayfield=='undefined') ? BDropdown_GetTextField(rs) : displayfield;
	
	this.Display = BDropdown_Display;
	this.GetValue = BDropdown_GetValue;
	this.SetValue = BDropdown_SetValue;
	this.SetOption = BDropdown_SetOption;
	this.IsNull = BDropdown_IsNull;
	this._height = 1;
	
	if(Request.Form(this._name).Count==1)
		this._value = Request.Form(this._name).Item;
	else
		this._value = 0;

	this._onchangesubmit = true;
}

function BDropdown_GetTextField(rs) {
	for(var n=0;n<rs.Fields.Count;n++) {
		if(rs.Fields(n).Type==adLongVarChar || rs.Fields(n).Type==adVarChar || rs.Fields(n).Type==adChar)
			return n;
		if(rs.Fields(n).Type==adLongVarWChar || rs.Fields(n).Type==adVarWChar || rs.Fields(n).Type==adWChar)
			return n;
	}
	return 1;
}

function BDropdown_Display() {
	Out("\n<select size=\""+this._height+"\" class=\"bgrid_input\" name=\"" + this._name + "\"");
	if(this._onchangesubmit) Out(" onchange=\"this.form.submit()\"");
	Out(">\n\t<option/>\n");

	if(!this._rs.BOF && !this._rs.EOF) {
		this._rs.MoveFirst();
		while(!this._rs.EOF) {
			if(!this.IsNull(this._rs.Fields(this._idfield))) {
				if(this._rs.Fields(this._idfield).Value == this._value)
					Out("\t<option selected value=\"" + this._rs.Fields(this._idfield).Value + "\">");
				else
					Out("\t<option value=\"" + this._rs.Fields(this._idfield).Value + "\">");
				if(this.IsNull(this._rs.Fields(this._displayfield)))
					Out("&nbsp;");
				else
					Out(this._rs.Fields(this._displayfield).Value);
				Out("</option>\n");
			}
			this._rs.MoveNext();
		}
	}
	Out("</select>\n");
}

function BDropdown_GetValue() {
	return this._value;
}

function BDropdown_SetValue(value) {
	this._value = value;
}

function BDropdown_IsNull(oField) {
	return "" + oField.Value == "null";
}

function BDropdown_SetOption(option,value) {
	switch(option) {
	case "onchange_submit":
		this._onchangesubmit = value;
		break;
	case "height":
		this._height = value;
		break;
	default:
		throw new Error("Unknown option " + option + "!");
	}
}
</script>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Norway Norway
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions