GridView devExpress中的按钮

本文关键字:按钮 devExpress GridView | 更新日期: 2023-09-27 18:28:34

我有一个GridView:

 @Html.DevExpress().GridView(settings =>
       {
           settings.Name = "GridView";
           settings.KeyFieldName = "Id";
           settings.SettingsBehavior.AllowSelectByRowClick = true;
           settings.SettingsBehavior.AllowFocusedRow = true;
           settings.SettingsBehavior.AllowSelectSingleRowOnly = true;
           settings.ClientSideEvents.RowClick = "function(s, e){rowSelected(s, e)}";
           settings.Columns.Add("CodeClient");
           settings.Columns.Add("Nom");
           settings.Columns.Add("Prenom");
           settings.Columns.Add("DateNaissance");
       }).Bind(Model).GetHtml()

我想要此GridView中的按钮。有人能帮我修一下吗?

GridView devExpress中的按钮

如果要在Gridview中添加button。您可以按如下方式添加custom columnbutton

C#代码

settings.Columns.Add(column => {
            column.FieldName = "Unbound";
            column.Caption = "Button";
            column.UnboundType = DevExpress.Data.UnboundColumnType.String;
            column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.False;
            column.Width = Unit.Percentage(10);
            column.SetDataItemTemplateContent((c) => {
                htmlHelper.DevExpress().Button(b => {
                    b.Name = "Button" + c.KeyValue;
                    b.Text = "Test";
                    b.ClientSideEvents.Click = string.Format(@"function(s, e) {{ alert({0}); }}", c.KeyValue);
                }).GetHtml();
            });
        });

有关更多信息,您可以通过以下链接:-

Gridview中的简单按钮:https://www.devexpress.com/Support/Center/Question/Details/T161954

具有编辑模式的网格视图按钮:-

https://www.devexpress.com/Support/Center/Question/Details/Q499774

Editing mode的主要内容将是其的设置

settings.CommandColumn.Visible = true;
settings.CommandColumn.NewButton.Visible = true;
settings.CommandColumn.DeleteButton.Visible = true;
settings.CommandColumn.EditButton.Visible = true;

希望能有所帮助。

您可以用这样的东西为新按钮添加功能性(这是我的一个应用程序代码中的一个示例)。它有3个不同的自定义按钮:

//html
<dx:ASPxGridView ID="grvResultados" runat="server" EnableCallBacks="false" EnableTheming="True"
                                                OnBeforeColumnSortingGrouping="grvResultados_BeforeColumnSortingGrouping" 
                                                OnPageIndexChanged="grvResultados_PageIndexChanged"
                                                 OnCustomColumnDisplayText="grvResultados_CustomColumnDisplayText"
                                                Styles-Cell-Wrap="False" Theme="MetropolisBlue" Width="100%">
                                                <SettingsBehavior ColumnResizeMode="Control" />
                                                <SettingsPager Mode="ShowPager" NumericButtonCount="10" PageSize="20" PageSizeItemSettings-Visible="true"
                                                    Visible="true">
                                                    <PageSizeItemSettings Visible="True">
                                                    </PageSizeItemSettings>
                                                </SettingsPager>
                                                <Settings ShowHeaderFilterButton="true" ShowFooter="True" ShowFilterRow="True" ShowFilterRowMenu="True"
                                                    ShowHorizontalScrollBar="false" EnableFilterControlPopupMenuScrolling="true" ShowFilterBar="Auto"
                                                    VerticalScrollBarMode="Auto" VerticalScrollBarStyle="Standard" />
                                                <Styles>
                                                    <Cell Wrap="False">
                                                    </Cell>
                                                </Styles>
                                            </dx:ASPxGridView>

这是代码.cs

//Code
 protected void grvResultados_CustomColumnDisplayText(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewColumnDisplayTextEventArgs e)
    {
        if (e.Column.FieldName.Contains("FECHA"))
        {
            if (!String.IsNullOrEmpty(e.Value.ToString()))
            {
                try
                {
                    e.DisplayText = ((DateTime)e.Value).ToString("dd/MM/yyyy HH:mm:ss");
                }
                catch
                {
                    e.DisplayText = e.Value.ToString();
                }
            }
            e.Column.UnboundType = DevExpress.Data.UnboundColumnType.DateTime;
        }
    }
 protected void grvResultados_BeforeColumnSortingGrouping(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewBeforeColumnGroupingSortingEventArgs e)
    {
        try
        {
            MuestraResultados(0);
        }
        catch (Exception ex)
        {
            mpPage.MuestraPopUp(GenerarError(this.Page.ToString(), ex.Message, ex.StackTrace.ToString()), "ERROR");
        }
    }
    protected void grvResultados_PageIndexChanged(object sender, EventArgs e)
    {
        try
        {
            MuestraResultados(grvResultados.PageIndex);
        }
        catch (Exception ex)
        {
            mpPage.MuestraPopUp(GenerarError(this.Page.ToString(), ex.Message, ex.StackTrace.ToString()), "ERROR");
        }
    }