Using javascript for managing asp:ListBox, Add/Remove ListItem

Here is a wonderful tutorial about using javascript with "select" html control:

There are also related javascript tutorials. Here is presented the javascript and html code for managing select control. The asp:ListBox is wrapped select control with additional functionality. There is no problem to use select control in your code instead this one. I personally prefer using asp:ListBox:

<asp:ListBox ID="lstItems" runat="server" DataSourceID="ODSItems" DataTextField="Name" DataValueField="Id" Width="170px"></asp:ListBox>

<asp:Button ID="btnAddItem" runat="server" Text=">" />

<br />

<asp:Button ID="btnRemoveItem" runat="server" Text="<" />
<asp:ListBox ID="SelectedItems" runat="server" Width="170px">
<asp:ListItem Value="all" Text="All"></asp:ListItem>

In the Page.Load Event you have to add the followed code:

btnAddItem.Attributes.Add("onclick", "javascript:moveOptions('" + lstItems.ClientID + "','" + SelectedItems.ClientID + "');return false;") btnRemoveItem.Attributes.Add("onclick", "javascript:moveOptions('" + SelectedItems.ClientID + "','" + lstItems.ClientID + "');return false;")

I have added additional functionality for one more option field: all items. And also this code is optimized for asp pages - see the client id-s handling. This is the new javascript code:

var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);

function addOption(theSel, theText, theValue)
var newOpt = new Option(theText, theValue);
var selLength = theSel.length;
theSel.options[selLength] = newOpt;

// Removing the option with all value
var selLength = theSel.length;
var i;
if (selLength>1) {
for(i=selLength-1; i>=0; i--)
if (theSel.options[i].value=="all"){
deleteOption(theSel, i);

function deleteOption(theSel, theIndex)

var selLength = theSel.length;
theSel.options[theIndex] = null;

//adding all
if (theSel.length==0){
addOption(theSel, "Всички","all");


function moveOptions(theSelFromId, theSelToId)


var selLength = theSelFrom.length;
var selectedText = new Array();
var selectedValues = new Array();
var selectedCount = 0;

var i;

// Find the selected Options in reverse order
// and delete them from the 'from' Select.
for(i=selLength-1; i>=0; i--)
if (theSelFrom.options[i].value=="all"){
selectedText[selectedCount] = theSelFrom.options[i].text;
selectedValues[selectedCount] = theSelFrom.options[i].value;
deleteOption(theSelFrom, i);

// Add the selected text/values in reverse order.
// This will add the Options to the 'to' Select
// in the same order as they were in the 'from' Select.
for(i=selectedCount-1; i>=0; i--)
addOption(theSelTo, selectedText[i], selectedValues[i]);

if(NS4) history.go(0);

ASP.NET GridView RowDeleting event fires twice!

This is a well known bug (for Microsoft) when using ImageButton. Of course you can use standard button or link button to go round the problem.

Here is a solution with image button:

<asp:ImageButton runat=server id="ImageButton1" CommandName="Delete"
ImageUrl="..." CommandArgument='<%# DataBinder.Eval(Container,
"RowIndex") %>' OnCommand="ImageButton1_Command">

protected void ImageButton1_Command(object sender, CommandEventArgs e) {
GridView1.DeleteRow(Int32.Parse(e.CommandArgument.ToString() ));

SQL Server Management Studio - How to connect to database server

1. Start SQL Server Management Server Studio
2. Click on the 'Register Servers' button
3. Right click on the node Database Engine and select New > Server Registration.
4. Select server type to be Database Engine
5. Server Name: Write down the IP address of the database server, followed by port number separated with comma (server ip, port)
6. Choose authentication type to be SQL Server Authentication
7. Login and Password: The database username you created in your Database Manager within your Control Panel.
That is all!

VS 2005 Required components missing

Problem: Visual studio 2005 cannot connect to sql server express database. This is so boring problem... Here is a short summarize of similiar issue:

However my problem continued. The reason was that I have had installed Standard Edition of Sql Server 2005. When I installed SQL Server Express Edition I received the problem. The solution I found was so simple, I had to change database options of Visual Studio:
Tools -> Options -> Database Tools -> Data Connections. I changed SQL Server Instance Name to the new instance name (name of sql server express edition). This needed restart of Visual Studio. Now it works fine :-)

There is a way to run ASP.NET on Apache server

There is a way to run ASP.NET on Apache server :-) . I read some posts about it and found a good articles to make this possible:
This is enough to do it

One problem: there are ASP.NET controls that don't work in this way. Use it only for simple pages.

VS 2005 "Extensibility DTE object unavailable"

This occured after removing Visual Studio .NET 2003. When I trying to show dataset I recieved this error message.
I read many posts for this problem but the only way I found was repairing VS. This didn't solve the my problem. It was neccessary to remove totally VS 2005 and install it again.