1. 根据选中的KeyValue 来获取其他field的value
// Gridview settings
settings.CustomJSProperties = (s, e) =>
{
Dictionary<object, int> visibleIndices = new Dictionary<object, int>();
for (int i = 0; i < ((MVCxGridView)s).VisibleRowCount; i++)
visibleIndices.Add(((MVCxGridView)s).GetRowValues(i, ((MVCxGridView)s).KeyFieldName), i);
e.Properties["cpIndices"] = visibleIndices;
};
//javascript调用
GridView.cpIndices[Key,"fieldName")
2. 根据某些field的value来改变cell的backcolor
//Gridview settings
settings.HtmlDataCellPrepared = (sender, e) =>
{
var gv = sender as MVCxGridView;
string ls_Status = gv.GetRowValues(e.VisibleIndex, "Status") == null ? "" : gv.GetRowValues(e.VisibleIndex, "Status").ToString();
string[] la_EditorField = new string[] { "TaxInvCust", "IseVAT", "TaxInvRemark" };
if (ls_Status != "1" && la_EditorField.Contains(e.DataColumn.FieldName))
{
e.Cell.BackColor = System.Drawing.Color.Transparent;
}
};
3.通过jquery获取gridview cell的value.
//Gridview settings, id format = gridviewname_fieldname_visableIndex
settings.HtmlDataCellPrepared = (sender, e) =>
{
e.Cell.Attributes.Add("id", string.Format("{0}_{1}_{2}", settings.Name, e.DataColumn.FieldName, e.VisibleIndex));
};
//JavaScript function
function GetCellText(as_GridViewName,as_fieldName,ai_Index)
{
var ls_Amt = "";
var ls_text = $("#" + as_GridViewName + "_" + as_fieldName + "_" + ai_Index).text();
ls_Amt = parseFloat(ls_text.substring(0, ls_text.indexOf(".") + 3).replace(/\,/g,"")).toFixed(2);
return ls_Amt;
}
4.设置hyperlink column
//Gridview settings
settings.Columns.Add(column =>
{
column.FieldName = "TaxInvNo";
column.Caption ="Tax Inv. No.";
column.Width = 90;
column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.True;
column.SetDataItemTemplateContent(container =>
{
if (container.VisibleIndex < 0)
return;
var ls_Url = DataBinder.Eval(container.DataItem, "Url").ToString();
if (ls_Url != null && ls_Url != "")
{
helper.DevExpress().HyperLink(hyperlink =>
{
var li_VisibleIndex = container.VisibleIndex;
var ls_KeyValue = container.KeyValue;
hyperlink.Name = "h1" + ls_KeyValue;
hyperlink.Properties.Text = DataBinder.Eval(container.DataItem, "TaxInvNo").ToString();
hyperlink.Properties.TextField = "TaxInvNo";
hyperlink.NavigateUrl = ls_Url.ToString();
hyperlink.Properties.Target = "_blank";
}).Render();
}
else
{
if (DataBinder.Eval(container.DataItem, "TaxInvNo") != null)
helper.ViewContext.Writer.Write(DataBinder.Eval(container.DataItem, "TaxInvNo").ToString());
}
});
});//Tax Inv. No