• Devexpress MVC Gridview


    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

      

  • 相关阅读:
    在你想要放弃的那一刻,想想为什么当初坚持走到了这里
    将来的你一定会感谢现在奋斗的自己
    学习改变命运,拼搏成就未来
    springmvc的DispatcherServlet源码——doDispatch方法解析
    SpringMVC02 AbstractController And MultiActionController
    SpringMVC简介01
    NIO
    数据库的锁机制
    Spring和MyBatis环境整合
    事务的隔离级别和mysql事务隔离级别修改
  • 原文地址:https://www.cnblogs.com/hesijian/p/8630578.html
Copyright © 2020-2023  润新知