473,399 Members | 2,858 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,399 software developers and data experts.

Extracting values from arraylist

Hi everybody,I have 2 dropdowns and on selected index change the second
dropdown is populated accordingly and so on.i am displaying the
selected value in a label for the user so that he comes to know the
hierarchy level.
i will show you this with a example so that u can understand it well
and help me out to come with a solution.the scenario is as below:
Label: a>>a1
Dropdown1:a,b,c,d
Dropdown2:suppose user clicks on (a) item in the first dropdown
then corresponding records to that item will be displayed in the 2nd
dropdown lets say a1,a2,a3 will be displayed and same will be displayed
in the label for example if user clicks on a1 in 2nd dropdown then
label text would be a>>a1 but if there are no records under a1 and
after that if user clicks on a2 then in the present situation the label
is displayed as a>>a1>>a2 which is wrong,this should have been a>>a2 .
This is happening because i am fetching the records from the database
on selected index change and appending it to the label text. I need
help and advice from all of you as early as possible. this can happen
upto n level so plz give me the solution with the code if you think
that this can be done in this or that way...

waitng for your earliest reply........

Oct 3 '06 #1
7 2083
Amit,

What you want is very easy to do if you use datatables.

Cor

"Amit" <am******@gmail.comschreef in bericht
news:11**********************@k70g2000cwa.googlegr oups.com...
Hi everybody,I have 2 dropdowns and on selected index change the second
dropdown is populated accordingly and so on.i am displaying the
selected value in a label for the user so that he comes to know the
hierarchy level.
i will show you this with a example so that u can understand it well
and help me out to come with a solution.the scenario is as below:
Label: a>>a1
Dropdown1:a,b,c,d
Dropdown2:suppose user clicks on (a) item in the first dropdown
then corresponding records to that item will be displayed in the 2nd
dropdown lets say a1,a2,a3 will be displayed and same will be displayed
in the label for example if user clicks on a1 in 2nd dropdown then
label text would be a>>a1 but if there are no records under a1 and
after that if user clicks on a2 then in the present situation the label
is displayed as a>>a1>>a2 which is wrong,this should have been a>>a2 .
This is happening because i am fetching the records from the database
on selected index change and appending it to the label text. I need
help and advice from all of you as early as possible. this can happen
upto n level so plz give me the solution with the code if you think
that this can be done in this or that way...

waitng for your earliest reply........

Oct 4 '06 #2
Well as you have identified, the problem is that you are APPENDING the
selected string.
You need to rewrite the whole label each time.
So lets say your label is called: lblResult, and your drop downs are
called ddl1 and ddl2 respectively.

So when ddl2 selected index changes, you want to rewrite the whole
label, something like this:

lblResult.Text = ddl1.SelectedText + " >" + ddl2.SelectedText;

Is this what you had in mind?

SN

Oct 4 '06 #3

Steven Nagy wrote:
Well as you have identified, the problem is that you are APPENDING the
selected string.
You need to rewrite the whole label each time.
So lets say your label is called: lblResult, and your drop downs are
called ddl1 and ddl2 respectively.

So when ddl2 selected index changes, you want to rewrite the whole
label, something like this:

lblResult.Text = ddl1.SelectedText + " >" + ddl2.SelectedText;

Is this what you had in mind?

SN
Dear Steven,
what you have written is almost correct the only thing is that only
first time the ddl1.selected text would be displayed in label and from
there on it would be only ddl2.selected text which i want to display in
the label. I will explain you in more detail.its like i have n level
categories in two droopdowns.first time only first dropdown is
displayed and on that selected index change the second one is
populated.from there onwards whenever a user selects a category that
category i am shifting to the first dropdown and corresponding records
to that category which user has selected i am displaying those records
in second dropdown.and i am checking the parentid's in database if any
corresponding records are there to that category in the database and so
on.for example suppose i have a1,a2 categories ubder a category.so the
first time user clicks on ist dropdown he will select a and in the 2nd
dropdown a1 and a2 will be displayed and when he clicks on a1 in the
2nd dropdown then a1 moves up to 1st dropdown and corresponding recoeds
to a1 will be displayed in the second dropdown. the problem is that
after selecting a1 if user clicks on a2 the n label shows:a>>a1>>a2
which is not correct it should have been a>>a2 and this can be upto n
level.This is happening bcoz i m appending the records in label.if you
have a better solution them plz help me by providing me with the code
that this can be done in this way...i tried to call a function in the
label but still it did not work...
your early reply would be a gr8 help.

Thanks
Amit

Oct 5 '06 #4
Hi Amit,

I'm sorry but after your explanation I am still not 100% sure what the
final result should be.

In the selected index change for DDL1 you would have this:
lblResult.Text = ddl1.SelectedText;

In the selected index change for DDL2 you would have this:
lblResult.Text = ddl1.SelectedText + " >" + ddl2.SelectedText;
This is rewriting the whole label each time, depending on which DDL you
select from.
So with this code, selecting A from DDL1 would show:
A

Then selecting A2 from DDL2 would show:
A >A2

Then selecting A4 from DDL2 would show:
A >A4

Is this what you wanted?

Cheers,
Steven

Oct 5 '06 #5
Dear Steven,
This is rewriting the whole label each time, depending on which DDL you
select from.
So with this code, selecting A from DDL1 would show:
A

Then selecting A2 from DDL2 would show:
A >A2

Then selecting A4 from DDL2 would show:
A >A4

Upto here what you have written is absolutely correct but suppose if
under A4, i have two more categories say A4.1 and A4.2 then by
selecting A4.1 from DDl2, label should display
A>>A4>>A4.1 and if there are no records under A4.1 and then if user
selects A4.2 then label should display A>>A4>>A4.2 .right now its
showing A>>A4>>A4.1>>A4.2 .bcoz i am appending the text in the
label.but if i do not append then i loose previous text.In this way i
have to retain the previous text in the label also This can be upto n
level. I mean A>A4>>A4.2>>A4.21>>A4.211 and so on. I think now it
will give you a clear picture and i hope i will get a solution from
you..

Thanks
Amit
Steven Nagy wrote:
Hi Amit,

I'm sorry but after your explanation I am still not 100% sure what the
final result should be.

In the selected index change for DDL1 you would have this:
lblResult.Text = ddl1.SelectedText;

In the selected index change for DDL2 you would have this:
lblResult.Text = ddl1.SelectedText + " >" + ddl2.SelectedText;
This is rewriting the whole label each time, depending on which DDL you
select from.
So with this code, selecting A from DDL1 would show:
A

Then selecting A2 from DDL2 would show:
A >A2

Then selecting A4 from DDL2 would show:
A >A4

Is this what you wanted?

Cheers,
Steven
Oct 5 '06 #6
Ok I think I understand you now.
The second drop down can contain elements that are sub elements of each
other?
Whats your table schema look like for these elements?

Currently I am imagining something like this:

ID
Name
ParentID

.... where anything with a null (or 0) ParentID goes into the first drop
down list, and everything else goes into the second drop down list.

In this example, you could write a method that recursively returns the
right string:

// Note: Code untested
private string GetLabel(int ItemID) {
SqlConnection dbc = GetDBConenction();
string SQL = "SELECT * FROM MyTable WHERE ID=" + ItemID.ToString();
SqlDataAdapter da = new SqlDataAdapter(SQL, dbc);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count>0) {
string Name = dt.Rows(0)("Name");
int ParentID = (int)dt.Rows(0)("ParentID");
if (ParentID==0) {
return Name;
}
else {
return GetLabel(ParentID) + " >" + Name;
}
}
return "";
}
Hope this helps.

SN

Oct 5 '06 #7
Hi steven,
I was off from my work for one week as i was on holidays so could not
see your reply.
now i have used it and its working fine till now.Thanks for your
extended help and i wish and hope that i will get the same help from
your side in future also..

Thanks
Amit

Steven Nagy wrote:
Ok I think I understand you now.
The second drop down can contain elements that are sub elements of each
other?
Whats your table schema look like for these elements?

Currently I am imagining something like this:

ID
Name
ParentID

... where anything with a null (or 0) ParentID goes into the first drop
down list, and everything else goes into the second drop down list.

In this example, you could write a method that recursively returns the
right string:

// Note: Code untested
private string GetLabel(int ItemID) {
SqlConnection dbc = GetDBConenction();
string SQL = "SELECT * FROM MyTable WHERE ID=" + ItemID.ToString();
SqlDataAdapter da = new SqlDataAdapter(SQL, dbc);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count>0) {
string Name = dt.Rows(0)("Name");
int ParentID = (int)dt.Rows(0)("ParentID");
if (ParentID==0) {
return Name;
}
else {
return GetLabel(ParentID) + " >" + Name;
}
}
return "";
}
Hope this helps.

SN
Oct 13 '06 #8

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

Similar topics

0
by: Mico | last post by:
I would be very grateful for any help with the following: I currently have the code below. This opens a MS Word document, and uses C#'s internal regular expressions library to find if there is a...
0
by: Bubbles | last post by:
Hello. New to ASP.NET and struggling on this one. I have a text file with a bunch of text in it. Throughout the file words followed by a ":" will appear. I need to pull every such string out...
3
by: Sonny Sablan | last post by:
AryUnderNav = New ArrayList() AryUnderNav.Add("Under $50") AryUnderNav.Add("$50 - $100") AryUnderNav.Add("$100 - $200") AryUnderNav.Add("$200 +") UnderNav.DataSource = AryUnderNav ...
0
by: Dave | last post by:
Hi all, I have a listbox that is complex bound by an arraylist. The problem is that when I delete an object from the arraylist, the listbox does not reflect those changes. I tried refreshing...
4
by: Jon Paal | last post by:
I am using a custom server control in my webpage which renders some html. while it creates the html, it develops an arraylist of values. Is there a way to capture the arraylist from the control...
6
by: Pavel Maly | last post by:
Hi, how do I access values in an ArrayList which is a part of another ArrayList? I know I can define a class and then it is quite simple, but this is just an auxiliary application to compute some...
8
by: Pim75 | last post by:
Hello, I'm defining a string array like: Dim strArray() As String = {"1", "2"} Can I add some values to this string array later in the code? It's not clear to me how to do this. I hope...
9
by: norulzs | last post by:
Hi, In a attempt to create a dynamic multi diminsion array i am using a ArrayList object as i do not know how many dimension i will need during runtime. My code is ArrayList mySubArray = new...
9
by: ajos | last post by:
Hello friends, After thinking about this for sometime, i decided to post this in the java forum. Well my problem here in detail is, i have 3 jsp pages where in a.jsp(for example) i have a combo...
1
by: cowboyrocks2009 | last post by:
Hi. I want to return values from multiple Arraylist. How can I do that ? later I want to use these values in another class. Can somebody help class myClass{ public ArrayList<Rectangle>...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.