62,243
社区成员




protected void btnSearch_Click(object sender, EventArgs e)
{
GridBing();
}
private void GridBing()
{
List<Goods> list = new List<Goods>();
list = GoodsBLL.getGoodsByOrder(this.txtName.Text, this.txtBegin.Text, this.txtEnd.Text);
double total = 0;
foreach (Goods item in list)
{
total += item.Price;
}
this.GridView1.DataSource = list;
this.GridView1.DataBind();
this.Label1.Visible = true;
string msg = "";
if (!string.IsNullOrEmpty(txtBegin.Text) && !string.IsNullOrEmpty(txtEnd.Text))
{
msg = "从 " + this.txtBegin.Text + " 至 " + this.txtEnd.Text;
}
msg += " 总计消费: " + total.ToString() + " 元";
this.Label1.Text = msg;
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "currentColor=this.style.backgroundColor;this.style.backgroundColor='#E8E0E0'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentColor");
Button btn = (Button)e.Row.FindControl("btnDel");
btn.Attributes.Add("onclick", "return confirm('你确定删除吗?')");
int id = Convert.ToInt32(e.Row.Cells[4].Text);
Users user = UserBLL.getUserById(id);
e.Row.Cells[4].Text = user.Name;
if (e.Row.Cells[5].Text.Length > 8)
{
e.Row.Cells[5].Text = e.Row.Cells[5].Text.Substring(0, 8) + "……";
}
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.PageIndex = e.NewPageIndex;
GridBing();
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "del")
{
int num = GoodsBLL.delById(Convert.ToInt32(e.CommandArgument));
this.GridBing();
}
}
}
<div id="showGv" style="text-align: center;">
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None"
Height="127px" Width="1024px" AutoGenerateColumns="False" AllowPaging="True"
OnPageIndexChanging="GridView1_PageIndexChanging"
OnRowDataBound="GridView1_RowDataBound"
onrowcommand="GridView1_RowCommand" DataKeyNames="id">
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:BoundField DataField="name" HeaderText="商品名称" />
<asp:BoundField DataField="price" HeaderText="商品价格">
<HeaderStyle Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="count" HeaderText="商品数量">
<HeaderStyle Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="datatime" HeaderText="购买时间">
<headerstyle width="100px" />
</asp:BoundField>
<asp:BoundField DataField="userid" HeaderText="购买人">
<HeaderStyle Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="remarks" HeaderText="商品描述" >
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:TemplateField HeaderText="删除">
<ItemTemplate>
<asp:Button ID="btnDel" runat="server" CommandName="del"
Text=" 删 除 " />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>