473,387 Members | 1,374 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Multiple Dropdownlist, selectedindex all the same but should be different


Hi,

I am actually binding to an ArrayList as below. The ArrayList stores
arrays of size 2. The thing is it works fine on postbacks. It's just
the first load that it defaults the 3 selected value to the last
selectIndex.

Thanks!
Linna
ArrayList alQuery = new ArrayList();
alQuery = oCust.RetrieveSavedQueryList();
IEnumerator myEnum = alQuery.GetEnumerator();

int i=0;
while ( myEnum.MoveNext() )
{
string[] item = new string[2];
item = (string[])myEnum.Current;
ListItem li = new ListItem(item[1],item[0]);
//default to selected view for first load
ddlView1.Items.Add(li);
ddlView2.Items.Add(li);
ddlView3.Items.Add(li);
if (String.Compare(item[0],_defaultView1,true)==0)
{
i1 = i;
}
if (String.Compare(item[0],_defaultView2,true)==0)
{
i2 = i;
}
if (String.Compare(item[0],_defaultView3,true)==0)
{
i3 = i;
}
i++;
}
ddlView1.DataBind();
ddlView1.SelectedIndex = i1;
ddlView2.DataBind();
ddlView2.SelectedIndex = i2;
ddlView3.DataBind();
ddlView3.SelectedIndex = i3;


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #1
1 1319
Linna,

As I said, the problem is in sharing the same items between several ddls.
When you make an item selected in one ddl, it becomes also selected in the
others. Make separate instances of ArrayList for every ddl.

Eliyahu

"Linna" <li***@galeforcesolutions.com> wrote in message
news:em**************@tk2msftngp13.phx.gbl...

Hi,

I am actually binding to an ArrayList as below. The ArrayList stores
arrays of size 2. The thing is it works fine on postbacks. It's just
the first load that it defaults the 3 selected value to the last
selectIndex.

Thanks!
Linna
ArrayList alQuery = new ArrayList();
alQuery = oCust.RetrieveSavedQueryList();
IEnumerator myEnum = alQuery.GetEnumerator();

int i=0;
while ( myEnum.MoveNext() )
{
string[] item = new string[2];
item = (string[])myEnum.Current;
ListItem li = new ListItem(item[1],item[0]);
//default to selected view for first load
ddlView1.Items.Add(li);
ddlView2.Items.Add(li);
ddlView3.Items.Add(li);
if (String.Compare(item[0],_defaultView1,true)==0)
{
i1 = i;
}
if (String.Compare(item[0],_defaultView2,true)==0)
{
i2 = i;
}
if (String.Compare(item[0],_defaultView3,true)==0)
{
i3 = i;
}
i++;
}
ddlView1.DataBind();
ddlView1.SelectedIndex = i1;
ddlView2.DataBind();
ddlView2.SelectedIndex = i2;
ddlView3.DataBind();
ddlView3.SelectedIndex = i3;


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: jm | last post by:
I have datagrid. On this datagrid there is a button and a dropdownlist. When I press the button, I want the selectedIndex of the dropdownlist. There is a button and a dropdownlist for each...
4
by: skyking1 | last post by:
I have a web form in which I'm selecting values of 10 different dropdownlists using a for each. I use DirectCast along with FindControl to get each dropdown and set the value. It seems that setting...
2
by: David Austin via .NET 247 | last post by:
Hello, I hope this is where I should post this. I have a problem with this code that I can't figure out...seems to be a bug in the dropdownlist control. I am trying to set multiple dropdownlists to...
5
by: Lie | last post by:
Hi all, I have problem in getting selectedindex of multiple listbox selection in a datagrid. I have a listbox with multiple selection mode inside datagrid. In Edit mode, I need to get back all...
9
by: james.e.coleman | last post by:
Hello, I have created a custom dropdownlist that is used multiple times within a single page. When trying to set the values of the controls with the page in which they are being used, they all...
4
by: Mark Waser | last post by:
I've discovered a very odd bug when attempting to put a dropdown list in a datagrid. In the page PreRender step, the selected index of the datagrid is successfully set during databinding. Yet,...
1
by: g | last post by:
I have a user control that contains a dropdownlist. Using a public property, I can get the selected item. However, I am unsure of how to use that same public property to set the selected item. ...
1
by: Jason Wilson | last post by:
I have two dropdownlists that are bound to the same datasource and I have a couple of questions: 1) Because they are bound to the same datasource, I am assuming that they only make 1 round trip...
1
by: pleaseexplaintome | last post by:
Hi all, I have a datagrid with a dropdownlist and would like to have the dropdownlist display a database value correctly while the grid is in edit mode. I have a templatecolumn as follows: ...
1
by: marcbb | last post by:
Hi all, I have a really strange problem working with Dropdownlists in a DataGrid. I'm trying to preselect some values from the DropDownlist for each row in the DataGrid, but it seems that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.