- 根据选中的KeyValue 来获取其他field的value
// Gridview settings<br> 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")
- 根据某些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));
};<br><br><br>
//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<br> 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
//获取gridview里面的combo box 显示的文本
//获取某个column在gridview的 index
RightGridView.GetColumnByField("FunUID").index
//获取gridview里面的combo box 显示的文本
RightGridView.batchEditHelper.GetCellTextContainer(visibleindex ,columnIndex).textContent
在Double Click event里面. 获取当前鼠标选择的值
//s.GetFocusedCell().rowVisibleIndex 获取当前选中行的index
//s.GetFocusedCell().column.fieldName 获取当前选中行的field
s.batchEditApi.GetCellValue(s.GetFocusedCell().rowVisibleIndex,s.GetFocusedCell().column.fieldName)
在Double Click event里面. 获取当前鼠标选择的列的值
//自定义计算footer的summary
//首先将需要自定义计算的field 设置为 DevExpress.Data.SummaryItemType.Custom
settings.CustomSummaryCalculate = (s, e) =>
{
ASPxSummaryItem summary = e.Item as ASPxSummaryItem;
if (e.IsTotalSummary)
{
int li_totalValue = 0;
decimal ld_totalValue = 0;
for (int i = 0; i < ((MVCxGridView)s).VisibleRowCount; i++)
{
if (summary.FieldName == "QTY")
{
if ((((MVCxGridView)s).GetRowValues(i, "TranType") == DBNull.Value ? "" : ((MVCxGridView)s).GetRowValues(i, "TranType").ToString()) == "IN")
li_totalValue += Convert.ToInt32(((MVCxGridView)s).GetRowValues(i, "QTY"));
else
li_totalValue -= Convert.ToInt32(((MVCxGridView)s).GetRowValues(i, "QTY"));
e.TotalValue = li_totalValue;
}
}
e.TotalValueReady = true;
}
};
//在Column里面显示Button(包含当添加新行时无法触发onclick event)
//在Column里面显示Button(包含当添加新行时无法触发onclick event)
partial view
settings.Columns.Add(column =>
{
column.Caption = "...";
column.FieldName = "btnDlvAddress";
column.UnboundType = DevExpress.Data.UnboundColumnType.String;
column.Width = 50;
column.SetDataItemTemplateContent(container =>
{
Html.DevExpress().Button(b =>
{
b.Name = "btnDlvAddress" + container.KeyValue;
b.Text = "...";
b.Width = Unit.Percentage(100);
b.ClientSideEvents.Click = "function(s,e){ OnSearchDlvAddress(); }";
b.ClientEnabled = true;
b.EnableClientSideAPI = true;
b.ClientVisible = true;
}).Render();
});
});
<br><br>
Index.cshtml
function OnSearchDlvAddress()
{
}
//使用Gridview的StartEdit event 处理当时新行的时候 call function
function OnTruReqGridView_BatchStartEdit(s,e)
{
e.cancel = true;
if(e.focusedColumn.fieldName == "btnDlvAddress")
{
e.cancel = true;
if(ModalTruReqGridView.batchEditApi.IsNewRow(e.visibleIndex))
OnSearchDlvAddress();
}
}
//判断Gridview里面某行的某列是否有修改
//agdv_Grid.batchEditApi.HasChanges(行号, 列名orID)
var lb_IsEdit = Gridview.batchEditApi.HasChanges(0, "ColumnName");
//lb_IsEdit 将返回true or false