Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi everyone,

I designed some dropdownlist and some listbox, in fact:

one dropdownlist modality

one listbox multiselect Region

one listbox multiselect CesType

And I need to compare both selected Value and get value in the 3rd dropdownlist (or it can be a listbox)CesName.

here is the code that I used BindCesName.

protected void bindCesName()
    {
        string sql = null;
        string region = "'";
        foreach (ListItem ligne in lstbxRegion.Items)
        {
            if (ligne.Selected)
            {
                region = region + ligne.Value + "','";
            }
        }

        string CesType = "'";
        foreach (ListItem ligne in lstbxCesType.Items)
        {
            if (ligne.Selected)
            {
                CesType = CesType + ligne.Value + "','";
            }
        }

        #region CES of selected Main Modality

        if (ddlModality.SelectedIndex > 0)
        {
            if ((lstbxRegion.SelectedIndex > 0) && (lstbxCesType.SelectedIndex > 0))
            {
                sql = "select distinct cesName.cesName, cesName.ID from cesname left join ces on cesname.Id = ces.cesName_ID left join bigmodality on ces.BigModality_ID = bigmodality.Id where ces.ID>0 and bigmodality.Modality_Name='" + ddlModality.SelectedItem.Text + "' and ces.Region_ID in(" + region + "0') and ces.cesType in ("+ CesType +" 0')order by cesname asc";
            }
            else if ((lstbxRegion.SelectedIndex == 0) && (lstbxCesType.SelectedIndex > 0))
            {
                sql = "select distinct cesName.cesName, cesName.ID from cesname left join ces on cesname.Id = ces.cesName_ID left join bigmodality on ces.BigModality_ID = bigmodality.Id where ces.ID>0 and bigmodality.Modality_Name='" + ddlModality.SelectedItem.Text + "' and ces.cesType in (" + CesType + " 0')order by cesname asc";
            }
            else if ((lstbxRegion.SelectedIndex > 0) && (lstbxCesType.SelectedIndex == 0))
            {
                sql = "select distinct cesName.cesName, cesName.ID from cesname left join ces on cesname.Id = ces.cesName_ID left join bigmodality on ces.BigModality_ID = bigmodality.Id where ces.ID>0 and bigmodality.Modality_Name='" + ddlModality.SelectedItem.Text + "' and ces.Region_ID in(" + region + "0')  order by cesname asc";
            }
            else if ((lstbxRegion.SelectedIndex == 0) && (lstbxCesType.SelectedIndex == 0))
            {
                sql = "select distinct cesName.cesName, cesName.ID from cesname left join ces on cesname.Id = ces.cesName_ID left join bigmodality on ces.BigModality_ID = bigmodality.Id where ces.ID>0 and bigmodality.Modality_Name='" + ddlModality.SelectedItem.Text + "' order by cesname asc";
            }
        }


the question comes from the fact that after selecting values in dropdownlist modality, listbox multiselect Region and listbox multiselect CesType, there is nothing (it shows "ALL") in the dropdownlist CesName. Does it mean that my bindCesName doesn't work well?

p.s: I've made autopostback be true.

could anyone help me ?


many thanks in advance!!!
Posted
Comments
Dasaradhi_r 10-Sep-12 10:40am    
Is your problem resolved?

1 solution

Hi,
I went through your code and there is nothing wrong about it.
So, My answer is based on the last one liner you wrote:

You have set the auto post back true: That will be the source of the issue.

1) First of all, answer yourself Do you need a post back there?
- To me postback should be avoided.
2) You might disabled viewstate on your page and hence state of these controls is not retained across post backs. So set enable view state property to true in the aspx page in the @Page directive.
HTML
EnableViewState="true"

Just see if the above two points help you. Otherwise, please let me know.
 
Share this answer
 
Comments
jessicachen12 10-Sep-12 11:03am    
thank you so much, it is true there is a mistake about the auto postback.
jessicachen12 13-Sep-12 5:28am    
Hi, how to et enable view state property to true in the aspx page in the @Page directive?
Dasaradhi_r 13-Sep-12 5:51am    
As stated in the second point, In your .aspx page, In the @Page directive, at the end just put - EnableViewState="true". Let me know, if you still not able to do it.
jessicachen12 13-Sep-12 11:21am    
thank you
Dasaradhi_r 13-Sep-12 11:56am    
Can you accept my answer if this has helped you to solve your problem?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900