2015-09-24 142 views
1

我试图完成联编辑上的ASP.NET 4.5 Web表单应用程序的DevExpress ASPxTreeList控制 - 这样的事情(从DevExpress的演示现场拍摄):的DevExpress ASPxTreeList - 内联编辑

enter image description here

我试图做的是两两件事:

  1. 我希望能够限制我的内联编辑到短短列 - 例如, 只有Budget列应该是可编辑的。我想只有Budget单元格变为文本框以允许数据输入 - 而所选行中的所有其他列应保持为,因为 - 作为标签基本上(现在,当启用内联编辑时,所有单元格变成可编辑的控件 - 它们变成一个文本框,这将建议编辑是可能的)

  2. 我希望能够单击(或双击)到该单元格以启用内联编辑 - 现在,我需要使用单独的命令按钮来“打开”编辑。我该怎么做(如果有的话)?

回答

2
  1. 如果你想要的标签,而不是编辑的控制,那么你可以简单地使用EditCellTemplate里面的标签控件。

这里是例如:

<dx:TreeListDataColumn FieldName="ContactName"> 
    <EditCellTemplate> 
     <dx:ASPxLabel ID="ASPxLabel1" runat="server" Value='<%# Eval("ContactName") %>' /> 
    </EditCellTemplate> 
</dx:TreeListDataColumn> 
  • 这种用于ASPxTreeList功能不通过的DevExpress实现。他们在其支持中心建议实施«ASPxTreeList - Implement BatchEdit mode (like in ASPxGridView)»。 Here你可以看看ASPxGridView的工作原理。
  • 因此,这里是基于this示例的解决方法。
    主要目标是使用DataCellTemplate作为值编辑器控制ASPxTextBox控件。 ASPxTextBox可以通过对每个复合编辑器元素应用特定样式进行完全自定义。这可以模拟所需的行为。您可以隐藏ASPxTextBox的边框和背景,并仅在ASPxTextBox为焦点时才显示边框。
    这里是例子:

    <script> 
        function GotFocus(s, e) { 
         s.inputElement.style.cursor = "text"; 
        } 
        function LostFocus(s, e) { 
         s.inputElement.style.cursor = "default"; 
        } 
    </script> 
    
    <dx:ASPxTreeList ID="ASPxTreeList1" ClientInstanceName="tree" runat="server" Width="100%" 
        DataSourceID="AccessDataSource1" AutoGenerateColumns="False" KeyFieldName="CategoryID" 
        OnCustomCallback="ASPxTreeList1_CustomCallback">    
         <Columns> 
          <dx:TreeListTextColumn FieldName="CategoryID" ReadOnly="True" VisibleIndex="0"> 
          </dx:TreeListTextColumn> 
          <dx:TreeListTextColumn FieldName="CategoryName" VisibleIndex="1"> 
           <DataCellTemplate> 
            <dx:ASPxTextBox 
             ID="txtBox" 
             Width="100%" 
             runat="server" 
             Value='<%# Eval("CategoryName") %>' 
             Cursor="default" 
             BackColor="Transparent" 
             Border-BorderColor="Transparent" 
             FocusedStyle-Border-BorderColor="ActiveBorder" 
             ClientSideEvents-GotFocus="GotFocus" 
             ClientSideEvents-LostFocus="LostFocus" /> 
           </DataCellTemplate> 
          </dx:TreeListTextColumn> 
          <dx:TreeListTextColumn FieldName="Description" VisibleIndex="2"> 
           <DataCellTemplate>      
            <dx:ASPxTextBox 
             ID="txtBox" 
             Width="100%" 
             runat="server" 
             Value='<%# Eval("Description")%>' 
             Cursor="default" 
             BackColor="Transparent" 
             Border-BorderColor="Transparent"       
             FocusedStyle-Border-BorderColor="ActiveBorder" 
             ClientSideEvents-GotFocus="GotFocus" 
             ClientSideEvents-LostFocus="LostFocus"/> 
           </DataCellTemplate>         
          </dx:TreeListTextColumn> 
         </Columns>    
         <Border BorderWidth="0px" /> 
        </dx:ASPxTreeList> 
        <dx:ASPxButton ID="ASPxButton1" runat="server" AutoPostBack="False" Text="Post Modifications" 
         Width="217px"> 
         <ClientSideEvents Click=" 
    function(s, e) { 
        tree.PerformCallback('post'); 
    }" /> 
        </dx:ASPxButton> 
    
    <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/nwind.mdb" 
        SelectCommand="SELECT * FROM [Categories]" 
        UpdateCommand="UPDATE [Categories] SET [CategoryName] = ?, [Description] = ? WHERE [CategoryID] = ?"> 
        <UpdateParameters> 
         <asp:Parameter Name="CategoryName" Type="String" /> 
         <asp:Parameter Name="Description" Type="String" /> 
         <asp:Parameter Name="CategoryID" Type="Int32" /> 
        </UpdateParameters> 
    </asp:AccessDataSource> 
    
    private List<Record> list = new List<Record>(); 
    
    protected void Page_Load(object sender, EventArgs e) 
    { 
        var column1 = ASPxTreeList1.DataColumns["CategoryName"]; 
        var column2 = ASPxTreeList1.DataColumns["Description"]; 
    
        var nodes = ASPxTreeList1.GetVisibleNodes(); 
    
        foreach (var node in nodes) 
        { 
         var txtBox1 = (ASPxTextBox)ASPxTreeList1.FindDataCellTemplateControl(node.Key, column1, "txtBox"); 
         var txtBox2 = (ASPxTextBox)ASPxTreeList1.FindDataCellTemplateControl(node.Key, column2, "txtBox"); 
    
         if (txtBox1 == null || txtBox2 == null) 
          continue; 
    
         int id = Convert.ToInt32(node.Key); 
         list.Add(new Record(id, txtBox1.Text, txtBox2.Text)); 
        } 
    } 
    
    protected void ASPxTreeList1_CustomCallback(object sender, TreeListCustomCallbackEventArgs e) 
    { 
        if (e.Argument == "post") 
        { 
         for (int i = 0; i < list.Count; i++) 
         { 
          AccessDataSource1.UpdateParameters["CategoryName"].DefaultValue = list[i].CategoryName; 
          AccessDataSource1.UpdateParameters["Description"].DefaultValue = list[i].Description; 
          AccessDataSource1.UpdateParameters["CategoryID"].DefaultValue = list[i].Id.ToString(); 
          //    AccessDataSource1.Update(); << Uncomment this line to update data! 
         } 
    
         ASPxTreeList1.DataBind(); 
        } 
    } 
    
    +0

    谢谢!问题1的解决方案非常完美,并且工作完美无瑕 - 非常感谢您 –