1.设置Row(某列)输出格式,例如,在数字前加美元符、每3位以逗号隔开及设置小数点后两位:
<dx:GridViewDataTextColumn FieldName="SHOUHUIJEC" Caption="收汇金额" VisibleIndex="8" PropertiesTextEdit-DisplayFormatString="${0:#,##0.00;-#,##0.00;0}" Width="8%" />
2. ASPxGridView数据绑定中,KeyFieldName的值区分大小写,即一定要与数据库的键值大小写一致。
3.设置每页显示数目
<dx:ASPxGridView>
<SettingsPager Position="Bottom" PageSize="10" Summary-Text=" 第{0}/{1}页(共{2}条)" PageSizeItemSettings-Caption="每页大小:">
<PageSizeItemSettings Visible="true" ShowAllItem="true" />
</SettingsPager>
</dx:ASPxGridView>
4. DevExpress的主题设置:
方法1:
protected void Page_PreInit(object sender, EventArgs e){
//设置DevExpress的皮肤,可以写在aspx.cs或global.asax中
DevExpress.Web.ASPxClasses.ASPxWebControl.GlobalTheme = "Office2010Blue";
}
方法2:直接在ASPxGridView中的Theme属性设置
5. DevExpress数据库绑定中字符串的写法
方法1:直接写连接字符串
方法2:
<asp:SqlDataSource ConnectionString="<%$ ConnectionStrings:MySql %>"/>
/*连接字符串在Web.config中*/
6.如果想设置排序时固定列宽,需要设置每一列的宽度
7.主从表,导出是否包含详细列表
<dx:ASPxCheckBox ID="chkSingleExpanded" runat="server" Text="只展开一项" AutoPostBack="true" OnCheckedChanged="chkSingleExpanded_CheckedChanged" />
protected void chkSingleExpanded_CheckedChanged(object sender, EventArgs e){
grid.SettingsDetail.AllowOnlyOneMasterRowExpanded = chkSingleExpanded.Checked;
if (grid.SettingsDetail.AllowOnlyOneMasterRowExpanded){
grid.DetailRows.CollapseAllRows();
}
}
8.显示列汇总
<dx:ASPxGridView>
<dx:ASPxSummaryItem FieldName="NAME" SummaryType="Count" DisplayFormat="{0:汇 总}" />
</dx:ASPxGridView>
9.无刷新操作
<asp:UpdatePanel ID="UpdatePanel" runat="server">
<ContentTemplate>
/*********中间代码忽略**********/
</ContentTemplate>
</asp:UpdatePanel>
10.取消ASPxGridView的Row排序
<ClientSideEvents ColumnSorting="function(s, e) {e.cancel = true; }" />
11.某行或某列颜色区分
//改变当前处理列的颜色
protected void ASPxGridView1_HtmlDataCellPrepared(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewTableDataCellEventArgs e)
{
if (e.DataColumn.FieldName == "LEFTMONEY")
{
if (float.Parse(e.CellValue.ToString()) < )
{
e.Cell.ForeColor = System.Drawing.Color.Red;
}
}
} //改变当前处理行的颜色
protected void ASPxGridView1_HtmlRowPrepared(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewTableRowEventArgs e)
{
if (e.RowType != DevExpress.Web.ASPxGridView.GridViewRowType.Data) return;
string ispick = e.GetValue("IsPromotion").ToString();
if (ispick == "")
{
e.Row.ForeColor = System.Drawing.Color.Red;
}
}
12.主从表,后台获取从表
ASPxGridView detailGrid = grid.FindDetailRowTemplateControl(index, "detailGrid") as ASPxGridView;
13.主从表,显示或隐藏从表某列
protected void detailGrid_Load(object sender, EventArgs e)
{
(sender as ASPxGridView).Columns["HKDATE"].Visible = chkHidden.Checked;
}
14.在表中点击ASPxCheckBox就可以直接改变ASPxCheckBox的值及更新数据
<dx:GridViewDataCheckColumn FieldName="KPSH" Caption="开票" VisibleIndex="1" >
<DataItemTemplate>
<dx:ASPxCheckBox ID="chkKPSH" ClientInstanceName="chkKPSH" runat="server" Value='<%# Eval("KPSH") %>' OnInit="chk_Init" ReadOnly="True" CheckedImage-ToolTip="Checked" UncheckedImage-ToolTip="UnChecked" />
</DataItemTemplate>
</d:GridViewDataCheckColumn>
<dx:GridViewDataCheckColumn FieldName="CWSH" Caption="审核" VisibleIndex="2" >
<DataItemTemplate>
<dx:ASPxCheckBox ID="chkCWSH" ClientInstanceName="chkCWSH" runat="server" Value='<%# Eval("CWSH") %>' OnInit="chk_Init" ReadOnly="True" CheckedImage-ToolTip="Checked" UncheckedImage-ToolTip="UnChecked" />
</DataItemTemplate>
</dx:GridViewDataCheckColumn>
<dx:ASPxCallback ID="cb" runat="server" ClientInstanceName="cb" OnCallback="cb_Callback" />
protected void chk_Init(object sender, EventArgs e)
{
ASPxCheckBox chk = sender as ASPxCheckBox;
GridViewDataItemTemplateContainer container = chk.NamingContainer as GridViewDataItemTemplateContainer;
string caoZuo = "锁定";
if ((bool)grid.GetRowValues(container.VisibleIndex, container.Column.FieldName)) { caoZuo = "解锁"; }
chk.ClientSideEvents.CheckedChanged = String.Format("function (s, e) {{ cb.PerformCallback(confirm('确定要 {0} 吗?')+'|{1}|{2}|' + s.GetChecked());grid.Refresh(); }}", caoZuo, container.Column.FieldName, container.KeyValue);
}
protected void cb_Callback(object source, DevExpress.Web.ASPxCallback.CallbackEventArgs e){
String[] p = e.Parameter.Split('|');
if (p[] != "true") return;
DataBaseClass db = new DataBaseClass();
if (p[] == "KPSH")
{
string sSql = "UPDATE table SET KPSH = @kpsh WHERE id = @id";
SqlParameter[] pa = new SqlParameter[];
pa[] = new SqlParameter("@kpsh", Convert.ToBoolean(p[]));
pa[] = new SqlParameter("@id", Convert.ToInt32(p[]));
db.ExeSql2(sSql, pa);
}
else
{
string sSql = "UPDATE table SET CWSH = @cwsh WHERE id = @id";
SqlParameter[] pa = new SqlParameter[];
pa[] = new SqlParameter("@cwsh", Convert.ToBoolean(p[]));
pa[] = new SqlParameter("@id", Convert.ToInt32(p[]));
db.ExeSql2(sSql, pa);
}
}
15.主从表,如果希望主从表导出格式可以自行设置请使用XtraReport