Camillia
asked on
How can I check all dropdownlist values are the same?
I have 4 dropdownlists. User selects from each dropdownlist. I want compare the ddl SelectedValues and see if they're all the same:
ddl -- select A item
ddl 2 --select A item
ddl 3 -- Select A item
ddl3 -- select A item
So, i want to compare the SelectedValue and see if the values are ALL equal..for example to A...or user has selected different selectedValues...
ddl -- select A item
ddl 2 --select A item
ddl 3 -- Select A item
ddl3 -- select A item
So, i want to compare the SelectedValue and see if the values are ALL equal..for example to A...or user has selected different selectedValues...
ASKER
ok, in my example..i have 4 ddls . I actually should've said the number the ddls is dynamic. it can be one or 2 or 100...
how can do that??
how can do that??
ASKER
this ddl is in a grid. when grid binds...grid can have 1 row or 10 rows or more. so maybe...
loop thru the grid rows to see how many ddls i have, then compare??
loop thru the grid rows to see how many ddls i have, then compare??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
let me try it now. I'm at work now. Thanks for sticking with this . Kamila.
ASKER
OK, i dont know how to get the FIRST ddl value. I get null. The loop below works BUT it gets me all the DDLs..not just the first one. Not sure how to change it to get the first value.
This is Telerik grid..it's like AJAX:
This is Telerik grid..it's like AJAX:
DropDownList ddlSelection = (grdOrderItems.MasterTableView.FindControl("ddlNextStatus") as DropDownList);
string test = ddlSelection.SelectedValue; //*** THIS GIVES ME NULL
foreach (GridDataItem dataItem in grdOrderItems.MasterTableView.Items)
{
DropDownList ddlSelectionOthers = (dataItem.FindControl("ddlNextStatus") as DropDownList); //** this works because of I'm in foreach loop ..there has to be a way..
if (ddlSelection.SelectedValue == ddlSelectionOthers.SelectedValue)
....
instead of that way try this and ignore the first ddl value in the for each loop
DropDownList ddlSelectionOthers;
for (int i = 0l i < 1; i++)
{
ddlSelectionOthers = (grdOrderItems.MasterTable View.Items [i].FindCo ntrol("ddl NextStatus ") as DropDownList);
}
DropDownList ddlSelectionOthers;
for (int i = 0l i < 1; i++)
{
ddlSelectionOthers = (grdOrderItems.MasterTable
}
ASKER
let me try it. Been at this all morning and I dont want to ask my coworker..he loves himself too much :) thanks again..Kamila.
ASKER
You have: for (int i = 0l i < 1; i++)
Is that for (int i=0; i<1; i++)
?
Is that for (int i=0; i<1; i++)
?
something likr that running the loop for first item
ASKER
yes, that gives me the first value of the ddl. It's beautiful:)
>>nore the first ddl value in the for each loop
let me work on that. Thanks,. Will post back.
>>nore the first ddl value in the for each loop
let me work on that. Thanks,. Will post back.
ASKER
You know what, that's my problem again..now I have the first item..how do I skip the first item in the foreach loop??
i think do nothng for that
if we ignore that then it will be a slight overhead but as both are same the comparison will be true and the processing will not fail so no harm done
i hope it helps - ragi
if we ignore that then it will be a slight overhead but as both are same the comparison will be true and the processing will not fail so no harm done
i hope it helps - ragi
ASKER
yeah, you're right.
ASKER
i have another problem. I will close this question because your answer solved my issue. Then came across another issue that i hadnt thought of. Thanks for your help.
{
// same
}
else
{
// different
}