繁体   English   中英

下拉菜单未刷新Grid View。

[英]Grid View not getting refreshed with drop down.

<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'的查询相同。 那么,任何解决方案如何加载值?

尝试这个:

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

        }
        GridView1.DataSourceID = SqlDataSource1.ID;
        GridView1.DataBind();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM