UI界面的主界面为:
<body>
<form id="form1" runat="server">
<div>
产品名称 :<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
产品类别:<asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="true">
<asp:ListItem Selected ="True" Value ="0">全部</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="查询" />
<br />
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333"
GridLines="None" AutoGenerateColumns="False">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="PID" HeaderText="编号" SortExpression = "PID" />
<asp:BoundField DataField="ProductName" HeaderText="产品名称" />
<asp:BoundField DataField="MarketPrice" HeaderText="市场价" />
<asp:BoundField DataField="SellingPrice" HeaderText="售价" />
<asp:BoundField HeaderText="类别" DataField = "Name" SortExpression = "Name" />
<asp:BoundField DataField="Introduction" HeaderText="简介" Visible="False" />
<asp:TemplateField HeaderText="是否上架">
<ItemTemplate>
<%# Convert.ToInt32( Eval("PID"))==1?"上架":"下架"%>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Addtime" HeaderText="添加时间" />
<asp:TemplateField HeaderText="操作">
<ItemTemplate>
<a href = 'Edit.aspx?pid=<%# Eval("PID") %>'>编辑</a>
<a href ="javascript:void(0)" class="delete" data-id = '<%# Eval("PID") %>'>删除</a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
</div>
</form>
</body>
其中重要的部分为:数据源的内容分别显示,是否上架进行值判定分别显示
编辑 查询 删除方法的调用(删除方法为ajax)
其中后台加载事件为:数据绑定
if (!IsPostBack)
{
DropDownList1.DataSource = ProductCategoryM.Select();
DropDownList1.DataValueField = "id";
DropDownList1.DataTextField = "Name";
DropDownList1.DataBind();
//绑定数据源
GridView1.DataSource = ProductM.Select();
GridView1.DataBind();
}
然后查询按钮添加查询事件:
//点击查询时进行有条件的查询,查询后进行数据绑定
var name = TextBox1.Text;
var xl = Convert.ToInt32(DropDownList1.SelectedIndex);
GridView1.DataSource = ProductM.Select(name,xl);
GridView1.DataBind();