看看这个示例:
效果:
标记:
<form id="form1" runat="server">
<div>
<dx:ASPxGridView ID="ASPxGridView1" runat="server">
<Columns>
<dx:GridViewDataColumn FieldName="name">
<DataItemTemplate>
<dx:ASPxTextBox ID="txt" runat="server" Text='<%# Eval("name")%>'>
</dx:ASPxTextBox>
</DataItemTemplate>
</dx:GridViewDataColumn>
<dx:GridViewDataColumn FieldName="birthdate">
<DataItemTemplate>
<dx:ASPxLabel ID="lbl" runat="server" Text='<%# Eval("birthdate","{0:yyyy-MM-dd}")%>'>
</dx:ASPxLabel>
</DataItemTemplate>
</dx:GridViewDataColumn>
<dx:GridViewDataColumn FieldName="account">
<DataItemTemplate>
<dx:ASPxLabel ID="lbl" runat="server" Text='<%# Eval("account","{0:F2}")%>'>
</dx:ASPxLabel>
</DataItemTemplate>
</dx:GridViewDataColumn>
</Columns>
</dx:ASPxGridView>
</div>
代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable table = new DataTable();
table.Columns.Add("name");
table.Columns.Add("account", typeof(double));
table.Columns.Add("birthdate", typeof(DateTime));
DataRow row = table.NewRow();
row["name"] = "aa";
row["account"] = 12.123d;
row["birthdate"] = DateTime.Now;
table.Rows.Add(row);
row = table.NewRow();
row["name"] = "bb";
row["account"] = 741.251d;
row["birthdate"] = DateTime.Now;
table.Rows.Add(row);
row = table.NewRow();
row["name"] = "cc";
row["account"] = 124.2514d;
row["birthdate"] = DateTime.Now;
table.Rows.Add(row);
row = table.NewRow();
row["name"] = "dd";
row["account"] = 65.1245d;
row["birthdate"] = DateTime.Now;
table.Rows.Add(row);
this.ASPxGridView1.DataSource = table;
this.ASPxGridView1.DataBind();
}
}