<asp:DropDownList ID="RequestType1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>All</asp:ListItem>
<asp:ListItem Value="Stock_Market">Stock Market</asp:ListItem>
<asp:ListItem Value="Night_Shift">Night Shift</asp:ListItem>
<asp:ListItem Value="Air_Port">Air Port</asp:ListItem>
<asp:ListItem>Other</asp:ListItem>
</asp:DropDownList>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1" Font-Size="Small" ForeColor="#333333" GridLines="None" Width="810px" ShowHeaderWhenEmpty="True">
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConString %>" SelectCommand="select req.request_no ,emp.employee_name,req.requested_date, req.requested_time, req.requested_from, req.requested_to,req.reason_data from Request_List req, Employee emp where req.added_by=emp.employee_id and group_no IS NULL"></asp:SqlDataSource>
我有一个 gridview 和一个下拉列表和一个 sqldatasource ,当页面加载时,gridview 将从 sqldata 源加载默认查询。当使用下拉列表选择每个选项时,将按如下方式加载相应的查询。
if (RequestType1.Text == "All")
{
SqlDataSource1.SelectCommand = "select req.request_no ,emp.employee_name,req.requested_date, req.requested_time, req.requested_from, req.requested_to,req.reason_data from Request_List req, Employee emp where req.added_by=emp.employee_id and group_no IS NULL";
}
else if (RequestType1.Text == "Stock_Market")
{
SqlDataSource1.SelectCommand = "select req.request_no ,emp.employee_name,req.requested_date, req.requested_time, req.requested_from, req.requested_to,req.reason_data from Request_List req, Employee emp where req.added_by=emp.employee_id and req.service_type='Stock_Market ' and group_no IS NULL";
}
else if (RequestType1.Text == "Night_Shift")
{
SqlDataSource1.SelectCommand = "select req.request_no ,emp.employee_name,req.requested_date, req.requested_time, req.requested_from, req.requested_to,req.reason_data from Request_List req, Employee emp where req.added_by=emp.employee_id and req.service_type='Night_Shift' and group_no IS NULL";
}
else if (RequestType1.Text == "Air_Port")
{
SqlDataSource1.SelectCommand = "select req.request_no ,emp.employee_name,req.requested_date, req.requested_time, req.requested_from, req.requested_to,req.reason_data from Request_List req, Employee emp where req.added_by=emp.employee_id and req.service_type='Air_Port' and group_no IS NULL";
}
else if (RequestType1.Text == "Other")
{
SqlDataSource1.SelectCommand = "select req.request_no ,emp.employee_name,req.requested_date, req.requested_time, req.requested_from, req.requested_to,req.reason_data from Request_List req, Employee emp where req.added_by=emp.employee_id and req.service_type='Other' and group_no IS NULL";
}
但是对于“全部”选项,gridview 没有刷新。它有这个查询
SqlDataSource1.SelectCommand = "select req.request_no ,emp.employee_name,req.requested_date, req.requested_time, req.requested_from, req.requested_to,req.reason_data from Request_List req, Employee emp where req.added_by=emp.employee_id and group_no IS NULL";
但是当我添加一些其他查询时,它确实会刷新。关系是sqldata源的默认查询和选项'All'的查询是一样的。那么,任何解决方案如何加载值?