我有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
{
....................
}
答案 0 :(得分:0)
ListControl.SelectedItem
的默认设置为null
,因此,如果未选择任何NullReferenceException
,您可能会在Text
属性上获得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
}