如何在devExpress gridview中添加删除命令按钮
本文关键字:添加 删除 命令 按钮 gridview devExpress | 更新日期: 2023-09-27 17:50:18
我使用DevExpress gridview,里面有一个命令按钮。我想用image代替它。这怎么可能呢?
到目前为止,我已经尝试了这么多:
GridViewCommandColumn commancol = new GridViewCommandColumn();
commancol.ButtonType = ButtonType.Image;
GridViewCommandColumnButton moveUpBtn;
moveUpBtn.Image.Url = "~/App_Themes/Images/GridControl/grid-delete.png";
commancol.Add(moveUpBtn);
但是它给出了错误。
我想从。cs页面而不是aspx页面添加一个下面的方式按钮。所以我试着从代码后面找到上面的方法。
<dx:GridViewCommandColumn ButtonType="Image">
<HeaderTemplate>
</HeaderTemplate>
<DeleteButton Visible="true" Text="" Image-Url="grid-delete.png"
Image-ToolTip="Delete Record">
</DeleteButton>
</dx:GridViewCommandColumn>
谢谢
您可以像下面这样简单地添加CommandColumn,但是您应该注意asp.net页面事件以使其正确工作。
protected void Page_Init(object sender, EventArgs e)
{
GridViewCommandColumn column = new GridViewCommandColumn("....");
column.DeleteButton.Visible = true;
column.DeleteButton.Image.Url = "set path here";
column.Visible = true;
column.VisibleIndex = 2;//place where you want it to display
ASPxGridView1.Columns.Add(column);
}
protected void Page_Load(object sender, EventArgs e)
{
// Bind Data here
BindData();
}
参考命令列的文档,然后您也可以获得另一个命令按钮,并在运行时根据需要设置它们的属性。
你可以这样使用:1)在itemtemplate中声明imageButton
2)申报commandname
和commandargument
3)声明getimagepath4)声明在cs页面的getimage函数为
<asp:TemplateField HeaderText="Edit" ItemStyle-VerticalAlign="Top">
<ItemTemplate>
<asp:ImageButton ID="ibDelete" runat="server" CommandName="Delete" CommandArgument='<%# Bind("") %>'
ImageUrl='<%#GetImagePath("delete.png")%>' Width="20" Height="20" OnClick="ibDelete_Click"
OnClientClick='<%# Eval("", "return confirm('"Are you sure to delete - {0} ?'");") %>'
ToolTip="Delete Item" />
</ItemTemplate>
public string GetImagePath(string imgName)
{
string Finalurl = this.TemplateSourceDirectory + "/images/" + imgName;
return Finalurl;
}
protected void row_command(object sender, gridviewrowcommand e)
{
if(e.commandname=="Delete")
{
if(e.commandargument!=null)
{
// do the work here
}
}
}
我想从代码后面添加一个下面类型的删除命令按钮。
<dx:GridViewCommandColumn ButtonType="Image">
<HeaderTemplate>
</HeaderTemplate>
<DeleteButton Visible="true" Text="" Image-Url="grid-delete.png"
Image-ToolTip="Delete Record">
</DeleteButton>
</dx:GridViewCommandColumn>
<dx:GridViewCommandColumn Name="deleteRow" ShowDeleteButton="True" VisibleIndex="3" ButtonType="Image">
<CustomButtons>
<dx:GridViewCommandColumnCustomButton Visibility="AllDataRows" Image-Width="20" Image-Url="~/img/delete-icon.png"
Image-Height="20">
<Image Height="20px" Width="20px">
</Image>
</dx:GridViewCommandColumnCustomButton>
</CustomButtons>
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle"></HeaderStyle>
</dx:GridViewCommandColumn>