- 如果你想要的標籤,而不是編輯的控制,那麼你可以簡單地使用
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();
}
}
謝謝!問題1的解決方案非常完美,並且工作完美無瑕 - 非常感謝您 –