根据下拉值搜索

时间:2014-10-04 10:18:31

标签: c# asp.net

我有一个下拉列表,其中有两个选项, 一个。选 湾未选中。

我希望每当用户选择任何选项时,搜索都应该在此基础上进行过滤。我在gridview中有一列Selection,其中包含Selected和Not Selected选项。价值来自表格。

请参阅下拉列表的HTML和按钮供您参考:

<div style="float: left;">
    <asp:DropDownList ID="ddlSort" runat="server" AutoPostBack="false" OnSelectedIndexChanged="ddlSort_SelectedIndexChanged">
        <asp:ListItem Text="--Select--" Value="1"></asp:ListItem>
        <asp:ListItem Text="Selected" Value="2"></asp:ListItem>
        <asp:ListItem Text="Not Selected" Value="3"></asp:ListItem>
    </asp:DropDownList>
    <asp:Button ID="btnSortSelection" runat="server" Text="Sort Selection" OnClick="btnSortSelection_Click" />
</div>

我尝试使用下面提到的代码,但页面刷新并且gridview中的下拉列表丢失了它的值。所以它没有返回我的搜索结果。: -

protected void ddlSort_SelectedIndexChanged(object sender, EventArgs e) {
    SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DefaultSQLConnectionString"].ConnectionString); //create connection
    SqlCommand cmd = new SqlCommand("Select * from Career.Applicant where Selection =@Selected", conn);
    cmd.Parameters.AddWithValue("@selection", ddlSort.SelectedValue);
}

我想停止下拉列表值以获得回发,并且它应该在排序

时起作用

请参阅更新面板的代码: -

<asp:UpdatePanel runat="server" ID="updateapplicants">
                <ContentTemplate>
                    <div style="border: 1px solid #A8A8A8; width: 920px;">
                        <asp:GridView ID="gv_Applicants" runat="server" AutoGenerateColumns="false" AllowPaging="true" Width="920"
                            PageSize="5" OnPageIndexChanging="gv_Applicants_PageIndexChanging" OnRowCommand="gv_Applicants_RowCommand"
                            EmptyDataText="No Applicants Found."
                            AllowSorting="true"
                            OnSorting="gv_Applicants_Sorting"
                            OnRowDataBound="gv_Applicants_RowDataBound" RowStyle-CssClass="a12" AlternatingRowStyle-CssClass="a22" ForeColor="#333333" GridLines="None" CssClass="table_box" HeaderStyle-Height="35px" DataKeyNames="JobId">
                            <AlternatingRowStyle BackColor="#F0F0F0" />
                            <Columns>

                                <asp:BoundField DataField="FirstName" HeaderText="First Name" HeaderStyle-Width="84" />
                                <asp:BoundField DataField="LastName" HeaderText="Last Name" HeaderStyle-Width="106" />
                                <asp:BoundField DataField="ContactNumber" HeaderText="Contact" HeaderStyle-Width="98" />
                                <asp:BoundField DataField="Email" HeaderText="Email" HeaderStyle-Width="150" />

                                <asp:TemplateField HeaderText="Position" SortExpression="Position" HeaderStyle-Width="107">
                                    <ItemTemplate>
                                        <%# Eval("Job.Position") %>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Location" SortExpression="Location" HeaderStyle-Width="100">
                                    <ItemTemplate>
                                        <%# Eval("Job.Location") %>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:BoundField DataField="AppliedDate" DataFormatString="{0:MMMM dd, yyyy}" HeaderText="Date of Application" ReadOnly="true" HeaderStyle-Width="121" />

                                <asp:TemplateField HeaderText="Action" HeaderStyle-HorizontalAlign="Center">
                                    <ItemTemplate>
                                        <asp:LinkButton ID='lnkView' CommandName='v' Text='View' runat='server' CommandArgument='<%# Eval("ApplicantId") %>'></asp:LinkButton>
                                        |
                        <asp:LinkButton ID='lnkdel' CommandName='d' Text='Delete' runat='server' CommandArgument='<%# Eval("ApplicantId") %>' OnClientClick="return confirm('Are you sure to delete?');"></asp:LinkButton>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Selection">
                                    <ItemTemplate>
                                        <asp:DropDownList ID="ddlSelection" runat="server" EnableViewState="true" AutoPostBack="true">
                                            <asp:ListItem Text="None" Value="1"></asp:ListItem>
                                            <asp:ListItem Text="Selected" Value="2"></asp:ListItem>
                                            <asp:ListItem Text="Not Selected" Value="3"></asp:ListItem>
                                        </asp:DropDownList>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:BoundField DataField="JobId" HeaderText="Job ID" Visible="false" ReadOnly="true" />

                            </Columns>
                            <EditRowStyle BackColor="#2461BF" />
                            <FooterStyle BackColor="#D8DADA" Font-Bold="True" />
                            <HeaderStyle BackColor="#D8DADA" Font-Bold="True" />
                            <PagerStyle BackColor="#D8DADA" HorizontalAlign="Center" />
                            <RowStyle BackColor="white" BorderStyle="Solid" BorderColor="#a8a8a8" BorderWidth="1px" Height="35" />
                            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                        </asp:GridView>

                    </div>
                    <br />

                    <br />

                    <div id="divDetails" runat="server" class="force-overflow">
                        <div class="scrollbar" id="style-1">

                            <div style="border-left: 1px solid #A8A8A8; border-right: 1px solid #A8A8A8;">

                                <asp:DetailsView ID="dv_Applicants" HeaderStyle-Font-Bold="true" HeaderStyle-BackColor="#F7E1E1" runat="server" AutoGenerateRows="false" AllowPaging="false"
                                    HeaderText="Applicant Details" OnDataBound="dv_Applicants_DataBound" Width="912px" BackColor="#F0F0F0" BorderStyle="Solid" BorderWidth="1" BorderColor="#F0F0F0"
                                    RowStyle-Height="30" Font-Size="10">
                                    <Fields>

                                        <asp:TemplateField HeaderText="Position" HeaderStyle-CssClass="c_width">
                                            <ItemTemplate>
                                                <%#Eval("Job.Position") %>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="Location" HeaderStyle-CssClass="c_width">
                                            <ItemTemplate>
                                                <%#Eval("Job.Location") %>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="Business Unit" HeaderStyle-CssClass="c_width">
                                            <ItemTemplate>
                                                <%#Eval("Job.BusinessUnit") %>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:BoundField DataField="FirstName" HeaderText="First Name" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
                                        <asp:BoundField DataField="LastName" HeaderText="Last Name" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
                                        <asp:BoundField DataField="ContactNumber" HeaderText="Contact" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
                                        <asp:BoundField DataField="Email" HeaderText="Email" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
                                        <asp:BoundField DataField="PAN" HeaderText="PAN" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
                                        <asp:BoundField DataField="DOB" DataFormatString="{0:MMMM dd, yyyy}" HeaderText="Date of Birth" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
                                        <asp:BoundField DataField="Graduation" HeaderText="Graduation" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
                                        <asp:BoundField DataField="GradOther" HeaderText="Other" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
                                        <asp:BoundField DataField="GradDate" DataFormatString="{0:MMMM dd, yyyy}" HeaderText="Graduation Date" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
                                        <asp:BoundField DataField="PostGraduation" HeaderText="Post Graduation" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
                                        <asp:BoundField DataField="PGOther" HeaderText="Other" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
                                        <asp:BoundField DataField="PGDate" DataFormatString="{0:MMMM dd, yyyy}" HeaderText="Post Graduation date" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
                                        <asp:BoundField DataField="AnyOtherQual" HeaderText="Any Other Qualification" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
                                        <asp:BoundField DataField="CurrentOrg" HeaderText="Organization" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
                                        <asp:BoundField DataField="CurrentDesignation" HeaderText="Designation" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />

                                        <asp:BoundField DataField="CurrentFunctionalDesig" HeaderText="Current Functional Designation" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />

                                        <asp:BoundField DataField="CurrentCTC" DataFormatString="{0} lakhs per annum" HeaderText="CTC" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
                                        <asp:BoundField DataField="YrsinCurrentRole" HeaderText="Current Experience" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
                                        <asp:BoundField DataField="TotalExp" HeaderText="Total Experience" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
                                        <asp:BoundField DataField="KeySkills" HeaderText="Skills" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
                                        <asp:BoundField DataField="City" HeaderText="City" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
                                        <asp:BoundField DataField="State" HeaderText="State" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
                                        <asp:BoundField DataField="Country" HeaderText="Country" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
                                        <asp:TemplateField HeaderText="Willing to Relocate" ControlStyle-CssClass="c_width" HeaderStyle-CssClass="c_width">
                                            <ItemTemplate>
                                                <%# Convert.ToBoolean(Eval("WillingtoRelocate")) == true ? "Yes" : "No" %>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:BoundField DataField="LocationPreference" HeaderText="Location Preference" HeaderStyle-Width="190" HeaderStyle-Font-Bold="true" />
                                        <asp:BoundField DataField="AppliedDate" DataFormatString="{0:MMMM dd, yyyy}" HeaderText="Date of Application" ReadOnly="true" HeaderStyle-Font-Bold="true" />
                                        <asp:HyperLinkField DataNavigateUrlFields="CVFilePath" Text="View Resume" ControlStyle-ForeColor="White" ControlStyle-CssClass="bg" Target="_blank" />
                                    </Fields>
                                </asp:DetailsView>
                            </div>
                        </div>
                    </div>
                </ContentTemplate>
            </asp:UpdatePanel>

0 个答案:

没有答案