Saya memiliki halaman web ASP dengan GridView1
terhubung ke SqlDataSource1
, dan DropDownList1
yang mempengaruhi SqlDataSource1
skrip 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>
Saya perlu menampilkan data baru ketika DropDownList1
nilai baru dipilih.
Saya rasa saya perlu sesuatu untuk ditulis di sana:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlDataSource1.Update();
}
SqlDataSource1.Update();
tidak membantu.
Apa yang harus dijalankan di DropDownList1_SelectedIndexChanged
?
DropDownList1
dihubungkan ke parameter kontrolSqlDatasource1
dan properti GridView:<asp:GridView ... DataSourceID="SqlDataSource1"
akan menyebabkan tampilan grid mengikat data pada setiap postback. Tidak diperlukan kode seperti yang dikatakan Aria - person fnostro   schedule 04.03.2015