我有一个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中使用一个Button。 有人可以帮我解决这个问题吗?
答案 0 :(得分:0)
如果您想在button
内添加Gridview
。您可以添加custom column
button
,如下所示:
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;
希望有所帮助。
答案 1 :(得分:0)
你可以用这样的东西为你的新按钮添加一个功能(这是我的一个应用程序的代码中的一个例子)。它有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");
}
}