如何将asp.net中的对象绑定到几个列表框和下拉列表之后的控件 [英] how to bind object in asp.net to control after several listbox and dropdownlist

查看:46
本文介绍了如何将asp.net中的对象绑定到几个列表框和下拉列表之后的控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

实际上,我设计了一些下拉列表和一些列表框:

一种下拉列表形式

一个列表框多选Region

一个列表框多选CesType

而且我需要比较选择的Value和在第三个下拉列表(或可以是列表框)CesName中获取值.

这是我使用BindCesName的代码.

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";
            }
        }



问题来自以下事实:在下拉列表模态中选择了值,列表框多选Region和列表框多选CesType之后,下拉列表CesName中没有任何内容(显示为"ALL").这是否意味着我的bindCesName工作不正常?

ps:我已经将autopostback设为true.

有人可以帮我吗?


在此先感谢!



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!!!

推荐答案


我遍历了您的代码,这没有错.
因此,我的答案是基于您写的最后一个衬纸:

您已将自动回发设置为true:这将成为问题的根源.

1)首先,回答自己.您是否需要在那儿发帖?
-对我来说,应避免发回邮件.
2)您可能在页面上禁用了viewstate,因此这些控件的状态不会在回发之间保留.因此,请在@Page指令的aspx页面中将enable view state属性设置为true.
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.
EnableViewState="true"


请看看以上两点是否对您有帮助.否则,请告诉我.


Just see if the above two points help you. Otherwise, please let me know.


这篇关于如何将asp.net中的对象绑定到几个列表框和下拉列表之后的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆