开发者

devexpress ASPxGridView column problem

开发者 https://www.devze.com 2022-12-30 10:55 出处:网络
I have an ASPXGRIDVIEW which is binded开发者_如何学C to an SQL query. I added to the grid an additional COLUMNCUSTOMBUTTON.

I have an ASPXGRIDVIEW which is binded开发者_如何学C 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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消