关于GridView绑定
------------------前台GridView的页面---------------------------
<asp:GridView ID="TbNewOrder" runat="server"
AutoGenerateColumns="False"
DataKeyNames="F_ID"
EmptyDataText="没有可显示的数据记录。"
OnSelectedIndexChanged="TbNewOrder_SelectedIndexChanged"
width="100%" SkinID="ShopCarGridView" OnRowDataBound="TbNewOrder_RowDataBound">
<EmptyDataTemplate>
<div style="color:Red; text-align:center; height:50px;">订单不存在或无权查询</div>
</EmptyDataTemplate>
<Columns>
<asp:TemplateField HeaderText="订单详情">
<ItemTemplate>
<a href='Detail.aspx?id=<%# Eval("F_ID") %>' title="查看订单详情">订单详情</a>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="F_OrderNo" HeaderText="订单号" SortExpression="F_OrderNo" />
<asp:TemplateField HeaderText="下单日期">
<ItemTemplate>
<%# tl.FormatDate(Eval("F_InputDate").ToString(),"yyyy-mm-dd") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="订单总额">
<ItemTemplate>
<%# Eval("F_TotalMoney", "{0:c}") %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="F_StatusName" HeaderText="订单状态" />
<asp:TemplateField HeaderText="操作">
<ItemTemplate>
<asp:HyperLink ID="lnkDelOrder" runat="server" ><span style="color:red">删除</span></asp:HyperLink>
<asp:HiddenField ID="hdStatus" runat="server" Value='<%# Eval("F_Status") %>'/>
<asp:HiddenField ID="hdId" runat="server" Value='<%# Eval("F_ID") %>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
------------后台cs文件---------------------
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using CNTVS.TOOLS.SQLDB;
using CNTVS.TOOLS.COMM;
public partial class Users_Order : System.Web.UI.Page
{
DataBase db = new DataBase();
protected Tools tl = new Tools();
SqlConnection conn = null;
protected void Page_Load(object sender, EventArgs e)
{
myBindData();
}
protected void myBindData()
{
conn = db.GetConn();
SqlDataReader dr = db.RunSql("select * from V_Order", conn);
this.TbNewOrder.DataSource = dr;
this.TbNewOrder.DataBind();
}
}