2010-05-14 103 views
1

我有一個綁定到SQL查詢的ASPXGRIDVIEW。 我給網格添加了一個額外的COLUMNCUSTOMBUTTON。 但是會發生什麼,對於所有的行,它會在那裏放置一個鏈接。 我試圖找到一種方法來添加到這一列的鏈接(按鈕)只有特定的行!devexpress ASPxGridView列問題

我無法理解怎麼辦呢

感謝

回答

3

添加自定義按鈕,在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> 

在你的代碼隱藏然後:

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]; 
    } 
} 
} 

你可以看到完整的演示在這裏: http://demos.devexpress.com/ASPxGridViewDemos/Columns/CommandColumnCustomButtons.aspx