The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

import-bot (20211) [Avatar] Offline
#1
[Originally posted by arocha]

I hava a drop down list that is been populated by an two dimension array. The
problem is that the drop down list make a post back at the page and after the
post the selected item returns to position 0.

Can anyone help me with this problem? The post back has no problem with a
listitem insert manually, but through a array doesn´t work. This is a example:

x[0,0]="123";
x[0,1]="KKK";
x[1,0]="456";
x[1,1]="TTT";
x[2,0]="789";
x[2,1]="ZZZ";

ddlConta.Items.Add(new ListItem(x[0,0],x[0,1]));
ddlConta.Items.Add(new ListItem(x[1,0],x[1,1]));
ddlConta.Items.Add(new ListItem(x[2,0],x[2,1]));
import-bot (20211) [Avatar] Offline
#2
Re: Drop Down Lists
[Originally posted by fgrimes]

Hi,

I don't see any problem with your code, but I don't have it all. I tried the
following code and it worked for me. Perhaps you could compare it with yours.

Fergal
-------------------

<%@ Page Language="C#" Debug="true" %>

<script runat="server">

protected override void OnLoad(EventArgs e) {

base.OnLoad(e);
if (ddlConta.Items.Count == 3) return;

string[,] x = new string[3,2];
x[0,0]="123";
x[0,1]="KKK";
x[1,0]="456";
x[1,1]="TTT";
x[2,0]="789";
x[2,1]="ZZZ";

ddlConta.Items.Add(new ListItem(x[0,0],x[0,1]));
ddlConta.Items.Add(new ListItem(x[1,0],x[1,1]));
ddlConta.Items.Add(new ListItem(x[2,0],x[2,1]));
}
</script>


<html>
<head></head>
<body>
<form runat='server'>
<aspsmilieropDownList>
id="ddlConta"
AutoPostBack="true"
runat="server"/>
</form>
</body>
</html>