Wednesday, 22 April 2015

OnHtmlDataCellPrepared example of ASPxGridView


ASPxGridView Source Code

Here is ASPxGridView which  implements the OnHtmlDataCellPrepared event.

<dx:ASPxGridView ID="gvEmp" AutoGenerateColumns="False" runat="server" 
            OnHtmlDataCellPrepared=" gvEmp_HtmlDataCellPrepared">
            <Columns>
                <dx:GridViewCommandColumn ShowSelectCheckbox="True" VisibleIndex="0">
                </dx:GridViewCommandColumn>
                <dx:GridViewDataTextColumn FieldName="fldFirstName" VisibleIndex="1">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="fldLastName" VisibleIndex="2">
                </dx:GridViewDataTextColumn>
                 <dx:GridViewDataTextColumn FieldName="fldMobileNo" VisibleIndex="3">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="fldEmailAddress" VisibleIndex="4">
                </dx:GridViewDataTextColumn>
                 <dx:GridViewDataTextColumn FieldName="fldSalary"  VisibleIndex="5">
                </dx:GridViewDataTextColumn>
 <dx:GridViewDataTextColumn FieldName="fldEmpId"  VisibleIndex="6">
                </dx:GridViewDataTextColumn>
            </Columns>

        </dx:ASPxGridView>




Here is a event method called gvEmp_HtmlDataCellPrepared which change the color of cell fldSalary if cell value is grater then 100000.

protected void gvEmp_HtmlDataCellPrepared(object sender,
    DevExpress.Web.ASPxGridViewTableDataCellEventArgs e) {
    if (e.DataColumn.FieldName != "fldSalary") return;
    if (Convert.ToInt32(e.CellValue) > 100000)
        e.Cell.BackColor = System.Drawing.Color.green;
}

No comments:

Post a Comment