views:

629

answers:

1

Hey all

I have an ASPXGRIDVIEW which is binded to an SQL query. I added to the grid an additional COLUMNCUSTOMBUTTON. But what happens is, that for all the rows it put a link there. I am trying to find a way to add to this column a link (button) ONLY to specific rows!

I am unable to understand how to do it

thanks

+1  A: 

To add a custom button, add this to your command column in the aspx side:

 <dxwgv:ASPxGridView ID="grid" ClientInstanceName="grid" runat="server" DataSourceID="AccessDataSource1" KeyFieldName="EmployeeID" AutoGenerateColumns="False" Width="100%" OnCustomButtonCallback="grid_CustomButtonCallback" OnInitNewRow="grid_InitNewRow">
     <Columns>
         <dxwgv:GridViewCommandColumn VisibleIndex="0">
             <EditButton Visible="True" />
             <NewButton Visible="True" />
             <CustomButtons>
                 <dxwgv:GridViewCommandColumnCustomButton Text="Create a Copy" ID="Copy" />
             </CustomButtons>
         </dxwgv:GridViewCommandColumn>

Then in your codebehind:

public partial class GridEditing_EditForm : BasePage {
 protected void Page_Load(object sender, EventArgs e) {

 }

 Hashtable copiedValues = null;
 string[] copiedFields = new string[] { "FirstName", "Title", "Notes", "LastName", "BirthDate", "HireDate" };
 protected void grid_CustomButtonCallback(object sender, ASPxGridViewCustomButtonCallbackEventArgs e) {
     if(e.ButtonID != "Copy") return;
     copiedValues = new Hashtable();
     foreach(string fieldName in copiedFields) {
         copiedValues[fieldName] = grid.GetRowValues(e.VisibleIndex, fieldName);
     }
     grid.AddNewRow();

 }
 protected void grid_InitNewRow(object sender, DevExpress.Web.Data.ASPxDataInitNewRowEventArgs e) {
     if(copiedValues == null) return;
     foreach(string fieldName in copiedFields) {
         e.NewValues[fieldName] = copiedValues[fieldName];
     }
 }
}

You can see the full demo here: http://demos.devexpress.com/ASPxGridViewDemos/Columns/CommandColumnCustomButtons.aspx

Mehul