[英]Refresh data in GridView on DropDownList selected index change
I have ASP webpage with GridView1
connected to SqlDataSource1
, and DropDownList1
that makes influence on SqlDataSource1
SQL script. 我有ASP网页,其中
GridView1
连接到SqlDataSource1
,而DropDownList1
对SqlDataSource1
SQL脚本有影响。
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="terminalLog.aspx.cs" Inherits="_2013web.terminalLog" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2" DataTextField="Id" DataValueField="Id" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="True" Height="95px" OnLoad="DropDownList1_Load" OnTextChanged="DropDownList1_TextChanged" Width="481px">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:logsConnectionString1 %>" SelectCommand="SELECT [ClientID], [Msg], [LogLevel], [Date] FROM [logs] WHERE ([ClientID] = @ClientID) ORDER BY [Date]">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" DefaultValue="80" Name="ClientID" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" Width="2104px">
<Columns>
<asp:BoundField DataField="ClientID" HeaderText="ClientID" SortExpression="ClientID" />
<asp:BoundField DataField="Msg" HeaderText="Msg" SortExpression="Msg" />
<asp:BoundField DataField="LogLevel" HeaderText="LogLevel" SortExpression="LogLevel" />
<asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:logsConnectionString1 %>" SelectCommand="SELECT [Id] FROM [clients] ORDER BY [Id]"></asp:SqlDataSource>
</asp:Content>
I need to show new data when DropDownList1
new value is selected. 选择
DropDownList1
新值时,我需要显示新数据。
I think I need something to be written there: 我想我需要在这里写点东西:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlDataSource1.Update();
}
SqlDataSource1.Update();
not helps. 没有帮助。
What should be executed in DropDownList1_SelectedIndexChanged
? DropDownList1_SelectedIndexChanged
应该执行什么?
根据您的问题, DropDownList1
AutoPostBack
为True
,不需要编写任何代码,并且当更改所选值时,GridView将自动更新。
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
GridView1.DataBind();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.