ASPxGridView
DataTableのデータを使用して更新していますが、これは正常に機能します。しかし、編集、更新、削除、ページング、並べ替えの機能を使用しようとすると、問題が発生します。ボタンは表示されますが、クリックしても機能しません。
これが私のSample.aspx
ファイルです:
[ASPx]
<dx:aspxgridview ID="grid" ClientInstanceName="grid" runat="server"
OnDataBinding="grid_DataBinding" Width="100%" EnableCallBacks="false">
<Settings ShowTitlePanel="True" />
<SettingsText Title="Tabla" />
<SettingsPager PageSize ="10" ShowSeparators="true" PageSizeItemSettings-Items="20" >
<PageSizeItemSettings Visible="true" />
</SettingsPager>
</dx:aspxgridview>
Sample.aspx.csの背後にあるコード:
[C#]
using System;
using System.Data;
using System.Web.Mvc;
using DataConnector;
using DevExpress.Web.ASPxGridView;
using DevExpress.Web.Data;
namespace Sample.Views.Actions
{
public partial class Sample: ViewPage
{
private DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
grid.DataBind();
grid.RowValidating += new ASPxDataValidationEventHandler(grid_RowValidating);
if (!this.IsPostBack)
{
GridViewCommandColumn c = new GridViewCommandColumn();
grid.Columns.Add(c);
c.Caption = "Operations";
c.EditButton.Visible = true;
c.UpdateButton.Visible = true;
c.NewButton.Visible = true;
c.DeleteButton.Visible = true;
c.CancelButton.Visible = true;
}
}
DataTable BindGrid()
{
DataConnection DM = new DataConnection();
if (DM.login("ADMIN", "PASS"))
dt = DM.getDataSet("SELECT * FROM Table_Name");
grid.DataSource = dt;
dt.PrimaryKey = new DataColumn[] { dt.Columns[0] };
return dt;
}
protected void grid_DataBinding(object sender, EventArgs e)
{
// Assign the data source in grid_DataBinding
BindGrid();
}
protected void grid_RowUpdating(object sender, ASPxDataUpdatingEventArgs e)
{
int id = (int)e.OldValues["id"];
DataRow dr = dt.Rows.Find(id);
dr[0] = e.NewValues[""];
dr[1] = e.NewValues[""];
dr[2] = e.NewValues[""];
dr[3] = e.NewValues[""];
dr[4] = e.NewValues[""];
ASPxGridView g = sender as ASPxGridView;
UpdateData(g);
g.CancelEdit();
e.Cancel = true;
}
void grid_RowValidating(object sender, ASPxDataValidationEventArgs e)
{
int id = (int)e.NewValues["id"];
if ((!e.OldValues.Contains("id") || ((int)e.OldValues["id"] != id))
&& (dt.Rows.Find(id) != null))
{
ASPxGridView grid = sender as ASPxGridView;
e.Errors[grid.Columns["id"]] = String.Format("Column 'Id' is constrained to be unique. Value '{0}' is already present.", id);
}
}
private void UpdateData(ASPxGridView g)
{
g.DataBind();
}
}}
サンプルはコントローラーページで呼び出されます。
[C#]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data;
using DataConnector;
namespace Sample.Controllers
{
public class ActionsController : Controller
{
public ActionResult Sample()
{
return View();
}
}
}
グリッドに表示されるデータ。
Sample.aspx
とだけでSample.aspx.cs
MVCなしで使用していて、関数が機能している新しいソリューションを作成しました。違いは「パブリック部分クラスサンプル:System.Web.UI.Page
」です。上記のコードを使用せずに試してみるとSystem.Web.UI.Page
、次のエラーが発生します。
The view must derive from ViewPage, ViewPage<TModel>, ViewuserControl,or ViewuserControl<TModel>.
私は何が間違っているのですか?ASPxGridViewの機能が機能しないのはなぜですか?
ドラフトが不十分な場合は事前に申し訳ありませんが、母国語が英語ではなく、私は新しいプログラマーです:)