0

我有 3 个下拉列表和 1 个按钮..,当页面加载时,它会转到最后一个其他部分...如果我选择任何一个下拉列表并单击 btn..即使我在数据库中有数据,它也会显示为空...我想我在选定的项目部分犯了一些错误……你能为此提出一些想法吗……

if (employee_name_ddl.SelectedItem.Text != "Select" & employee_paricularpro_ddl.SelectedItem.Text == "Select" & employee_status_ddl.SelectedItem.Text == "All Status")
            {
                ............
            }
            else if (employee_name_ddl.SelectedItem.Text == "Select" & employee_paricularpro_ddl.SelectedItem.Text != "Select" & employee_status_ddl.SelectedItem.Text == "All Status")
            {
                ............................
            }
            else if (employee_name_ddl.SelectedItem.Text == "Select" & employee_paricularpro_ddl.SelectedItem.Text == "Select" & employee_status_ddl.SelectedItem.Text != "All Status")
            {
               ............................
            }
            else if (employee_name_ddl.SelectedItem.Text != "Select" & employee_paricularpro_ddl.SelectedItem.Text != "Select" & employee_status_ddl.SelectedItem.Text == "All Status")
            {
                ...............................
            }
            else if (employee_name_ddl.SelectedItem.Text != "Select" & employee_paricularpro_ddl.SelectedItem.Text == "Select" & employee_status_ddl.SelectedItem.Text != "All Status")
            {
               ........................
            }
            else if (employee_name_ddl.SelectedItem.Text == "Select" & employee_paricularpro_ddl.SelectedItem.Text != "Select" & employee_status_ddl.SelectedItem.Text != "All Status")
            {
               ...................
            }
            else if (employee_name_ddl.SelectedItem.Text != "Select" & employee_paricularpro_ddl.SelectedItem.Text != "Select" & employee_status_ddl.SelectedItem.Text != "All Status")
            {
       .........................
            }
            else
            {
                ....................
            }
4

1 回答 1

0

的默认ListControl.SelectedItem值为null,因此当未选择任何属性时,您可能会NullReferenceExceptionText某处获得属性。DropDownList

您还使用按位比较&而不是正确的逻辑&&

下面是一个例子来说明&和的区别&&

if(employee_name_ddl.SelectedItem != null && employee_name_ddl.SelectedItem.Text == "Select")
{
    // no exception whether or not employee_name_ddl.SelectedItem is null
}

if(employee_name_ddl.SelectedItem != null & employee_name_ddl.SelectedItem.Text == "Select")
{
    // exception when employee_name_ddl.SelectedItem is null,
    // because the second condition will be evaluated anyway
}

C#中&和&&运算符有什么区别

于 2012-04-17T06:59:03.593 回答