我正在尝试创建一个c#webform,它根据用户输入显示数据库中的信息。我的目标是让用户在商店编号框中键入一个数字,该编号将用于select语句中的where cause。
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication4.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<br />
Store #<br />
<input id="Text1" type="text" /><br />
<br />
<br />
</div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="Prop ID" HeaderText="Prop ID" SortExpression="Prop ID" />
<asp:BoundField DataField="Parcel/Account" HeaderText="Parcel/Account" SortExpression="Parcel/Account" />
<asp:BoundField DataField="State" HeaderText="State" SortExpression="State" />
<asp:BoundField DataField="Juris Cd" HeaderText="Juris Cd" SortExpression="Juris Cd" />
<asp:BoundField DataField="Address 1" HeaderText="Address 1" SortExpression="Address 1" />
<asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="Zip Code" HeaderText="Zip Code" SortExpression="Zip Code" />
<asp:BoundField DataField="Owner" HeaderText="Owner" SortExpression="Owner" />
<asp:BoundField DataField="Open Date" HeaderText="Open Date" SortExpression="Open Date" />
<asp:BoundField DataField="Close Date" HeaderText="Close Date" SortExpression="Close Date" />
<asp:BoundField DataField="Lease Begin" HeaderText="Lease Begin" SortExpression="Lease Begin" />
<asp:BoundField DataField="Lease End" HeaderText="Lease End" SortExpression="Lease End" />
<asp:BoundField DataField="Year" HeaderText="Year" SortExpression="Year" />
<asp:BoundField DataField="Prop Type" HeaderText="Prop Type" SortExpression="Prop Type" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:masterConnectionString %>" SelectCommand="SELECT * FROM [Prop_Info$]"></asp:SqlDataSource>
</form>
</body>
</html>
先谢谢
答案 0 :(得分:1)
像这样设置sqldatasource:
<asp:SqlDataSource ID="SqlDataSource1"
ConnectionString="<%$ ConnectionStrings:MyConn %>"
SelectCommand="SELECT FirstName FROM Users"
FilterExpression="FirstName='{0}'"
runat="server">
<FilterParameters>
<asp:ControlParameter Name="FirstName" ControlID="txtFirstName" PropertyName="Text" />
</FilterParameters>
</asp:SqlDataSource>
<asp:TextBox runat="server" Id="txtFirstName"></asp:TextBox>