近日,是项目中要用到 DEVEXPRESS的ASPxGridView控件,要求能自动显示行号,现将代码共享一下。
aspx页面:===========================================
<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" KeyFieldName="Id" Width="100%"
oncustomunboundcolumndata="ASPxGridView1_CustomUnboundColumnData"
ClientIDMode="AutoID">
<Columns>
<dx:GridViewDataTextColumn Caption="序号" FieldName="hh" UnboundType="Integer">
</dx:GridViewDataTextColumn>
<dx:GridViewDataColumn Caption="工作类型" FieldName="TaskType">
<DataItemTemplate>
<%#GetProjectNodeName((int)Eval("TaskType"))%>
</DataItemTemplate>
</dx:GridViewDataColumn>
</Columns>
</dx:ASPxGridView>
cs代码部分:=========================================
/// <summary>
/// 显示行号
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ASPxGridView1_CustomUnboundColumnData(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewColumnDataEventArgs e)
{
if (e.Column.Caption == "序号" && e.IsGetData)
e.Value = (e.ListSourceRowIndex + 1).ToString();
}