<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. Когда каждый параметр выбирается с выпадающим списком, соответствующие запросы будут загружаться следующим образом.Grid View не обновляется при выпадающем списке.
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";
}
Но сетка не обновляется для опции «Все». У этого есть этот вопрос
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 и запрос для опции «Все» одинаковы. Итак, любые решения, как загрузить значения?