2010-05-14 5 views
1

J'ai un ASPXGRIDVIEW qui est lié à une requête SQL. J'ai ajouté à la grille un bouton COLUMNCUSTOM supplémentaire. Mais ce qui se passe, c'est que pour toutes les lignes il y a un lien. J'essaie de trouver un moyen d'ajouter à cette colonne un lien (bouton) UNIQUEMENT à des lignes spécifiques!devexpress problème de colonne ASPxGridView

Je ne peux pas comprendre comment le faire

grâce

Répondre

3

Pour ajouter un bouton personnalisé, ajoutez ceci à votre colonne de commande dans le côté ASPX:

<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> 

Ensuite, dans votre 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]; 
    } 
} 
} 

Vous pouvez voir la démo complète ici: http://demos.devexpress.com/ASPxGridViewDemos/Columns/CommandColumnCustomButtons.aspx

Questions connexes