DEV-aspxgridview中无数据源时的操作
devexpress相关信息网站https://www.devexpress.com/Support/Center/Example/Details/E1522
该网址使用按钮添加删除编辑aspxgridview中的信息,并且有相关的演示:http://codecentral.devexpress.com/E1522/
上面的例子依然是在有数据库控件的基础上进行操作,但是与无数据库是操作的关联很大。
上面这张图片是演示删除操作
下面是代码 :
前台代码:
<dx:ASPxGridView ID="ASPxGridView1" runat="server" Width="100%"
AutoGenerateColumns="False" ClientIDMode="AutoID" KeyFieldName="pk_notice"
ClientInstanceName="grid"
OnRowDeleting="grid_RowDeleting" >
<SettingsDetail ShowDetailRow="True" />
<SettingsBehavior AllowDragDrop="False" AllowSort="False" AllowFocusedRow="True"
AllowSelectByRowClick="True" AllowSelectSingleRowOnly="True"
ConfirmDelete="True"></SettingsBehavior>
<SettingsText EmptyDataRow="无相关记录!" ConfirmDelete="确定删除吗?"></SettingsText>
<SettingsDetail ShowDetailRow="True"></SettingsDetail>
<Columns>
<dx:GridViewCommandColumn VisibleIndex="0">
<DeleteButton Text="删除" Visible="True">
</DeleteButton>
<ClearFilterButton Visible="True">
</ClearFilterButton>
</dx:GridViewCommandColumn>
<dx:GridViewDataTextColumn Caption="pk_notice" FieldName="pk_notice"
Visible="False" VisibleIndex="1"></dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="标题" FieldName="cTitle" VisibleIndex="2">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn
Caption="发布人" FieldName="cWriter" VisibleIndex="3">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn
Caption="发布时间" FieldName="dNewDate" VisibleIndex="4">
</dx:GridViewDataTextColumn>
</Columns>
<SettingsBehavior AllowDragDrop="False" AllowFocusedRow="True"
AllowSort="False" ConfirmDelete="True" AllowSelectSingleRowOnly="True" AllowSelectByRowClick="True" />
<SettingsText EmptyDataRow="无相关记录!" ConfirmDelete="确定删除吗?" />
</dx:ASPxGridView>
后台代码:
protected void grid_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
{
string txt = e.Keys[0].ToString();
//DataRow found = table.Rows.Find(e.Keys[0]);
string sqldel = "delete from EI_Notice where pk_notice='" + txt + "' ";
getsqlcom(sqldel);
string sql = "select top 100 pk_notice,cTitle ,cWriter,dNewDate,cDetails from EI_Notice order by dNewDate desc";
ASPxGridView1.DataSource = getData(sql);
ASPxGridView1.DataBind();
e.Cancel = true;
}
添加,编辑的按钮与此相似 事件为:
protected void grid_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e);新增
protected void grid_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e);编辑
其中:
e.Cancel = true;是必须要有的,否则会弹出“不支持指定的方法!”
相关问题连接:
https://www.devexpress.com/Support/Center/Question/Details/Q421703
详细的问题可以留言讨论!

浙公网安备 33010602011771号