从下拉框中选择一个选项并单击搜索后,如何更新gridview [英] How to update gridview, after selecting an option from drop-box and clicking search
问题描述
从下拉列表中选择过滤器并点击搜索按钮后,我需要帮助才能更新我的网格视图。
我有一个包含不同person_types的下拉列表,当我从列表中选择person_type时,我想点击搜索并自动更新网格视图。 />
这是我的gridview的代码:
Hi,
I need help to update my grid-view after selecting a filter from a drop-down list and clicking the search button.
I have a drop-down list which contains distinct person_types and when I select a person_type from the list I want to click search and for it to automatically update the grid-view.
This is the code for my gridview:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px"
CellPadding="4" DataSourceID="SqlDataSource2"
Width="2092px" AllowSorting="True"
onselectedindexchanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="Employee_ID" HeaderText="EmployeeID"
SortExpression="Employee_ID" />
<asp:BoundField DataField="Student_ID" HeaderText="StudentID"
SortExpression="Student_ID" />
<asp:BoundField DataField="Title" HeaderText="Title"
SortExpression="Title" />
<asp:BoundField DataField="Legal_FName" HeaderText="First Name"
SortExpression="Legal_FName" />
<asp:BoundField DataField="Preffered_FName" HeaderText="Preffered Name"
SortExpression="Preffered_FName" />
<asp:BoundField DataField="LName" HeaderText="Last Name"
SortExpression="LName" />
<asp:BoundField DataField="Person_Type" HeaderText="Type of person"
SortExpression="Person_Type" />
<asp:BoundField DataField="Phone_Number" HeaderText="Phone_Number"
SortExpression="Phone_Number" />
<asp:BoundField DataField="Mobile_Number" HeaderText="Mobile_Number"
SortExpression="Mobile_Number" />
<asp:BoundField DataField="Street" HeaderText="Street"
SortExpression="Street" />
<asp:BoundField DataField="Suburb" HeaderText="Suburb"
SortExpression="Suburb" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
</Columns>
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<RowStyle BackColor="White" ForeColor="#330099" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<SortedAscendingCellStyle BackColor="#FEFCEB" />
<SortedAscendingHeaderStyle BackColor="#AF0101" />
<SortedDescendingCellStyle BackColor="#F6F0C0" />
<SortedDescendingHeaderStyle BackColor="#7E0000" />
</asp:GridView>
This is the code for my dropdown list:
This is the code for my dropdown list:
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource1" DataTextField="Person_Type"
DataValueField="Person_Type">
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="Search" onclick="Button1_Click" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:Award_Management2ConnectionString %>"
SelectCommand="SELECT Distinct [Person_Type] FROM [People]">
</asp:SqlDataSource>
Currently the code for my search button is:
aspx:
Currently the code for my search button is:
aspx:
<asp:Button ID="Button1" runat="server" Text="Search" onclick="Button1_Click" />
aspx.cs:
aspx.cs:
protected void Button1_Click(object sender, EventArgs e)
{
GridView1.DataBind();
}
Can someone please help me get the search button to update the grid-view please ?
Can someone please help me get the search button to update the grid-view please ?
推荐答案
ConnectionStrings:Award_Management2ConnectionString %>\"
SelectCommand=\"SELECT Distinct [Person_Type] FROM [People]\">
</asp:SqlDataSource>
ConnectionStrings:Award_Management2ConnectionString %>" SelectCommand="SELECT Distinct [Person_Type] FROM [People]"> </asp:SqlDataSource>
Currently the code for my search button is:
aspx:
Currently the code for my search button is:
aspx:
<asp:Button ID="Button1" runat="server" Text="Search" onclick="Button1_Click" />
aspx.cs:
aspx.cs:
protected void Button1_Click(object sender, EventArgs e)
{
GridView1.DataBind();
}
Can someone please help me get the search button to update the grid-view please ?
Can someone please help me get the search button to update the grid-view please ?
Just use a SelectParameter in your sqlDatasource1’s SelectCommand so it references the selected value of your dropdown list, like so...
Just use a SelectParameter in your sqlDatasource1's SelectCommand so it references the selected value of your dropdown list, like so...
<asp:sqldatasource id="sqlDataSource1" runat="server">
ConnectionString="<%
ConnectionStrings:Award_Management2ConnectionString %>\" SelectCommand=\"Select * From sometable Where SomeID=@SelectedId\">
<SelectParameters>
<asp:controlparameter controlid=\"DropDownList1\" defaultvalue=\"0\" name=\"SelectedId\" propertyname=\"SelectedValue\" />
</SelectParameters>
</asp:sqldatasource>
ConnectionStrings:Award_Management2ConnectionString %>" SelectCommand="Select * From sometable Where SomeID=@SelectedId"> <SelectParameters> <asp:controlparameter controlid="DropDownList1" defaultvalue="0" name="SelectedId" propertyname="SelectedValue" /> </SelectParameters> </asp:sqldatasource>
这篇关于从下拉框中选择一个选项并单击搜索后,如何更新gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!