[英]How to add functionality to custom new row button in DevExpress GridView control
I am trying to emulate another form that the other developer here created. 我正在尝试模仿此处其他开发人员创建的另一种形式。 In the DevExpress gridview, he added a new row button to the filter row, rather than to each row.
在DevExpress网格视图中,他向过滤器行而不是每一行添加了一个新行按钮。 I figured out how to do that by copying the custom button into the appropriate place in the filter row.
我想出了如何通过将自定义按钮复制到过滤器行中的适当位置来执行此操作的方法。
My question is how do I add the functionality to it? 我的问题是如何向其中添加功能? I found the addnewrow() method in the documentation, but it required a DataTable() class that I couldn't figure out how to get.
我在文档中找到了addnewrow()方法,但是它需要一个DataTable()类,但我不知道该如何获取。 Can you help me?
你能帮助我吗? I just started working with your ASPxGridView control today so this is all new to me.
我今天才刚开始使用您的ASPxGridView控件,所以这对我来说是全新的。
Here is some of the code I found for adding a new row on DevExpress's gridview. 这是一些我在DevExpress的gridview上添加新行的代码。 But it feels like I am on the wrong track.
但是感觉就像我走错了路。 And my first question about it is where do I find the DataTable class?
我的第一个问题是在哪里可以找到DataTable类? Is there a simpler way to do this?
有没有更简单的方法可以做到这一点?
DataTable GetTable()
{
//You can store a DataTable in the session state
DataTable table = Session["Table"] as DataTable;
if (table == null)
{
table = new DataTable();
DataColumn colid = table.Columns.Add("ID", typeof(Int32));
DataColumn nameid = table.Columns.Add("Name", typeof(String));
table.PrimaryKey = new DataColumn[] { colid };
colid.ReadOnly = true;
for (int i = 0; i < 23; i++)
{
DataRow aRow = table.NewRow();
aRow["ID"] = i;
aRow["Name"] = String.Format("Name{0}", i);
table.Rows.Add(aRow);
}
Session["Table"] = table;
}
return table;
}
protected void grid_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
{
ASPxGridView grid = sender as ASPxGridView;
DataTable table = GetTable();
table.Rows.Add(new Object[] { e.NewValues["ID"], e.NewValues["Name"] });
Session["Table"] = table;
e.Cancel = true;
grid.CancelEdit();
}
You should get a bit of general knowledge before you do this. 在执行此操作之前,您应该先了解一些常识。 Look here for data binding explanation and here for ASPxGridView editing demos .
在这里查看数据绑定说明,在此处查看ASPxGridView编辑演示 。 Storing data in session (like in sample you found) is rarely a way to go.
在会话中存储数据(就像在您发现的示例中一样)很少是一种方法。
As for add new row you can use ASPxClientGridView.AddNewRow client side method. 至于添加新行,您可以使用ASPxClientGridView.AddNewRow客户端方法。 So, assign ClientInstanceName to your ASPxGridView (eg
grid1
) and call grid1.AddNewRow()
on button click event - ASPxButton.ClientSideEvents.Click . 因此,将ClientInstanceName分配给您的ASPxGridView (例如
grid1
),并在按钮单击事件-ASPxButton.ClientSideEvents.Click上调用grid1.AddNewRow()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.