Command Column showing the Delete button |
<dx:ASPxGridView ID="GridView1" runat="server" KeyFieldName="DataObjectId" Settings-ShowFilterRow="true" /> <Columns> <dx:GridViewCommandColumn ButtonType="Image"> <ClearFilterButton Image-Url="~/Images/Icons/clear_filter.png" Visible="True" /> <DeleteButton Image-Url="~/Images/Icons/delete.png" Visible="true" /> </dx:GridViewCommandColumn>
... </Columns> </dx:ASPxGridView>
You can hide the entire command column, or the entire column of delete buttons in your code-behind like so:
GridView1.GetCommandColumn().DeleteButton.Visible = false;(where GetCommandColumn is a custom extention that searches for the GridViewCommandColumn).
And all the delete buttons are now invisible!
But what if you want to hide a button per-row? Lets say you only wanted to be able to delete Scheduled events, and not Completed ones. You could use the OnHtmlRowCreated event, then find the column index of the command column, then guess at the contorl index of the delete button, like this:
e.Row.Cells[indexColumn].Controls[0].Visible = someTest();
Or you can use a new (since 2009) event called OnCommandButtonInitialize:
<dx:ASPxGridView ID="GridView1" runat="server" KeyFieldName="DataObjectId" Settings-ShowFilterRow="true" OnCommandButtonInitialize="GridView1_OnCommandButtonInitialize"/> <Columns> <dx:GridViewCommandColumn ButtonType="Image"> <ClearFilterButton Image-Url="~/Images/Icons/clear_filter.png" Visible="True" /> <DeleteButton Image-Url="~/Images/Icons/delete.png" Visible="true" /> </dx:GridViewCommandColumn>
... </Columns> </dx:ASPxGridView>
Then create the function in your code:
protected void grdClientReviewsList_OnCommandButtonInitialize(object sender, ASPxGridViewCommandButtonEventArgs e) { if (e.ButtonType != ColumnCommandButtonType.Delete) return; var yourDataObject = (yourDataObjectType)GridView1.GetRow(e.VisibleIndex); e.Visible = yourDataObject.Status != StatusType.Completed; }
And now you have per-row visibility on command column buttons!
Gridview shoing selective Delete button |
Please go here to post comments.
No comments:
Post a Comment