-4
我已經想出瞭如何創建下拉框,將它們鏈接到它們各自的數據源,以及創建鏈接到存儲過程的數據源。我不知道如何將按鈕鏈接到數據源,以便在單擊時運行存儲過程。我與2017年VS如何將按鈕單擊鏈接到數據源以運行存儲過程
工作的HTML標記:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ChangeShiftStat.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Shift
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="ShiftDataSource" DataTextField="Shift" DataValueField="Shift">
</asp:DropDownList>
<br />
<br />
New Status
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" DataSourceID="StatusDataSource" DataTextField="Status" DataValueField="Status">
</asp:DropDownList>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Change Status" />
<asp:SqlDataSource ID="ShiftDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:TheBoardConnectionString %>" SelectCommand="SELECT * FROM [Shifts]"></asp:SqlDataSource>
<asp:SqlDataSource ID="StatusDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:TheBoardConnectionString %>" SelectCommand="SELECT * FROM [Statuses]"></asp:SqlDataSource>
<asp:SqlDataSource ID="RunSP" runat="server" ConnectionString="<%$ ConnectionStrings:TheBoardConnectionString %>" SelectCommand="changeshiftstat" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="Shift" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="DropDownList2" Name="NewStat" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
C#代碼:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
感謝您的幫助。這些例子討論了取回結果。我真的不需要那個。你能指出我在哪裏放置代碼的方向嗎? –
有關如何在sql中執行非查詢的示例,請參閱https://msdn.microsoft.com/en-us/library/80x06z3b.aspx。如果你沒有任何參數,那就跳過這些行。 –
https://msdn.microsoft.com/en-us/library/zwwsdtbk(v=vs.80).aspx < - 本教程將向您展示如何將事件處理程序添加到您的程序中。你會想要一個按鈕點擊事件。 –