更改视觉工作室中的数据库条目
问题描述:
我正在构建一个显示健身器材表中的数据库信息的网络应用程序。到目前为止,我能够生成一个网页,并包含所有项目的下拉列表,并且这些信息会自动填充信息字段。更改视觉工作室中的数据库条目
我该如何使它成为查看网站的人可以使用添加/更新/删除/提交等几个按钮来添加,删除和修改表格条目?
下面是C#代码到目前为止,我已经产生:
public partial class Inventory : System.Web.UI.Page
{
Item currentInventory = new Item();
protected void Page_Load(object sender, EventArgs e)
{
UpdateInventory(0);
}
private void UpdateInventory(int index)
{
DataView inventoryTable = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
DataRowView row = (DataRowView)inventoryTable[index];
currentInventory.fac_ID = row["fac_ID"].ToString();
currentInventory.inv_Quantity = row["inv_Quantity"].ToString();
currentInventory.inv_Purchase_Date = row["inv_Purchase_Date"].ToString();
lblFacilityID.Text = currentInventory.fac_ID;
lblQuantity.Text = currentInventory.inv_Quantity;
lblPurchaseDate.Text
= Convert.ToDateTime(row["inv_Purchase_Date"]).ToShortDateString();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
UpdateInventory(DropDownList1.SelectedIndex);
}
}
这里是在.aspx代码我到目前为止:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Inventory.aspx.cs" Inherits="Inventory" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="Server">
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="equip_Name" DataValueField="equip_ID" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString=" <%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT Inventory.*, Equipment.* FROM Equipment INNER JOIN Inventory ON Equipment.equip_ID = Inventory.equip_ID"> </asp:SqlDataSource>
<table>
<tr>
<td>Facility:
</td>
<td>
<asp:Label ID="lblFacilityID" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>Quantity:
</td>
<td>
<asp:Label ID="lblQuantity" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>Purchase Date:
</td>
<td>
<asp:Label ID="lblPurchaseDate" runat="server"></asp:Label>
</td>
</tr>
</table>
<br />
<asp:DetailsView ID="ManageProducts" runat="server" Height="50px" Width="125px">
</asp:DetailsView>
</asp:Content>
答
如果你的要求很简单,你只要希望允许用户管理数据。
使用ASP.NET的动态数据网站分析应用程序的数据模型,并根据数据模型中的数据动态生成网页。这些自动生成的网页可以为每个表格显示,插入,删除和编辑数据。
答
的答案,这很可能是超出了计算器的范围。
我在MVC中工作过很多,并且webforms也不太一样。你想要做的是以某种方式从网页上采取这些改变(也许使用AJAX?),然后在希望与你已经写的不同的课程中实现改变。
我的建议是看一篇MSDN文章,而不是希望这里会有3页的答案。