我有一个包含两个子视图的主视图。我想在主行上有命令按钮,这会导致扩展到一个或另一个子表。当我处理ItemCommand事件时,我将所有细节表隐藏到Visible = False,但它们仍然在输出上可见。
我已尝试在ItemCommand事件中设置细节表的展开和可见性,如下所示:
if (e.CommandName == "ExpandSomething")
{
item.Expanded = true;
foreach (var table in MyGrid.MasterTableView.DetailTables)
if (table.Name != "Something")
table.Visible = false;
}
这对网格没有影响。
然后我想也许隐藏需要在事件周期的后期完成,所以我尝试了这样:
private string _activeChildView = null;
protected void ShowSingleChildTable(string name) //this is called from item command
{
_activeChildView = name;
}
private void Page_PreRender(object sender, EventArgs e)
{
if (_activeChildView != null)
foreach (var table in AdminGrid.MasterTableView.DetailTables)
if (table.Name != _activeChildView)
table.Visible = false;
}
两种方式都不起作用 - 两个网格始终可见。
在玩不同的事件时,我发现DataBinding事件是唯一一个将可见性设置为false的地方,但不幸的是,它在ItemCommand之前触发,所以我无法弄清楚是否有细节按钮被按下了。
条件详细信息视图的任何其他想法,如描述的那样?
编辑,这是标记,如果你认为它会有所帮助。我删除了不需要的列定义:<asp:EntityDataSource ID="EntityDataSourceThinges" runat="server"
ConnectionString="name=MyProjectEntities"
EntitySetName="Thinges" DefaultContainerName="MyProjectEntities"
EnableDelete="true" EnableUpdate="true" EnableInsert="true"
Include="ThingSomethings"
OrderBy="it.Title"
Where="it.Title like '%' + @Title + '%' or @Title is null">
<WhereParameters>
<asp:ControlParameter ControlID="txtSearch" DefaultValue="%" Name="Title" PropertyName="Text" Type="String" />
</WhereParameters>
</asp:EntityDataSource>
<asp:EntityDataSource ID="EntityDataSourceThingSomethings" runat="server"
ConnectionString="name=MyProjectEntities"
EntitySetName="ThingSomethings" DefaultContainerName="MyProjectEntities"
EnableDelete="true" EnableUpdate="true"
AutoGenerateWhereClause="true">
<WhereParameters>
<asp:SessionParameter Name="ThingID" SessionField="ThingID" Type="Int32" />
</WhereParameters>
</asp:EntityDataSource>
<asp:EntityDataSource ID="EntityDataSourceImages" runat="server"
ConnectionString="name=MyProjectEntities"
EntitySetName="MyProjectImages" DefaultContainerName="MyProjectEntities"
EnableDelete="true" EnableUpdate="true" EnableInsert="true"
AutoGenerateWhereClause="true"
OrderBy="it.Sequence">
<WhereParameters>
<asp:SessionParameter Name="ThingID" SessionField="ThingID" Type="Int32" />
</WhereParameters>
</asp:EntityDataSource>
Search by title:
<asp:TextBox runat="server" ID="txtSearch" /><asp:Button runat="server" Text="Search" />
<telerik:RadGrid ID="DnnGrid1" runat="server"
DataSourceID="EntityDataSourceThinges"
ImagesPath="~/images"
AllowPaging="false" AllowSorting="true"
AllowAutomaticUpdates="true" AllowAutomaticInserts="true" AllowAutomaticDeletes="true">
<MasterTableView AutoGenerateColumns="false" CommandItemDisplay="TopAndBottom"
HierarchyLoadMode="ServerOnDemand" ExpandCollapseColumn-Visible="false"
DataKeyNames="ThingID">
<Columns>
...
<telerik:GridButtonColumn Text="Expand Something" CommandName="ExpandSomething" />
<telerik:GridButtonColumn Text="Expand Something Else" CommandName="ExpandSomethingElse" />
...
<telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" ConfirmText="Are you sure you want to permenently delete this record?" />
</Columns>
<DetailTables>
<telerik:GridTableView runat="server" Name="Images" DataKeyNames="MyProjectImageID" DataSourceID="EntityDataSourceImages"
AutoGenerateColumns="false"
AllowAutomaticUpdates="true" AllowAutomaticInserts="true" AllowAutomaticDeletes="true"
CommandItemDisplay="TopAndBottom">
<ParentTableRelation>
<telerik:GridRelationFields MasterKeyField="ThingID" DetailKeyField="ThingID" />
</ParentTableRelation>
<Columns>
...
</Columns>
</telerik:GridTableView>
<telerik:GridTableView runat="server" Name="Something" DataSourceID="EntityDataSourceThingSomethings"
AutoGenerateColumns="false"
AllowAutomaticUpdates="true" AllowAutomaticDeletes="true"
CommandItemDisplay="TopAndBottom" DataKeyNames="SomethingID,ThingID">
<ParentTableRelation>
<telerik:GridRelationFields MasterKeyField="ThingID" DetailKeyField="ThingID" />
</ParentTableRelation>
<Columns>
...
</Columns>
<EditFormSettings EditFormType="AutoGenerated" />
<CommandItemSettings ShowAddNewRecordButton="false" />
</telerik:GridTableView>
</DetailTables>
<EditFormSettings EditFormType="AutoGenerated" />
</MasterTableView>
</telerik:RadGrid>
答案 0 :(得分:1)
请尝试使用以下代码段。
<强> ASPX 强>
void myMethod(String arg1) {
SomeObject foo = getSomeObject(arg1);
Optional<SomeOtherObject> opBar =
Optional.ofNullable(foo)
.map(foo -> foo.getSomeOtherObject())
opBar.ifPresent(bar -> bar.doSomething());
Optional<YetAnother> opBaz =
opBar.filter(bar -> bar.isGood())
.map(bar -> getAnotherByName(bar.getAnotherName())
.filter(baz -> baz.exitEarly());
opBaz.ifPresent(baz -> foo.recordEarlyExit(baz.getName()));
if (!opBaz.isPresent()) {
doNormalThing();
}
}
方法1:每行只显示1个子网格。
<强> ASPX.CS 强>
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource" OnDetailTableDataBind="RadGrid1_DetailTableDataBind"
OnItemCommand="RadGrid1_ItemCommand" AutoGenerateColumns="false">
<MasterTableView DataKeyNames="ID">
<Columns>
<telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
</telerik:GridBoundColumn>
<telerik:GridButtonColumn Text="Expand Something" CommandName="ExpandSomething" />
<telerik:GridButtonColumn Text="Expand Something Else" CommandName="ExpandSomethingElse" />
</Columns>
<DetailTables>
<telerik:GridTableView runat="server" Name="Images" AutoGenerateColumns="false" CommandItemDisplay="TopAndBottom">
<Columns>
<telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
</telerik:GridBoundColumn>
</Columns>
</telerik:GridTableView>
<telerik:GridTableView runat="server" Name="Something" AutoGenerateColumns="false" CommandItemDisplay="TopAndBottom">
<Columns>
<telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
</telerik:GridBoundColumn>
</Columns>
</telerik:GridTableView>
</DetailTables>
</MasterTableView>
</telerik:RadGrid>
方法2:在完整网格中仅显示1个子网格。
<强> ASPX.CS 强>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
dynamic data = new[] {
new { ID = 1, Name ="Name1"},
new { ID = 2, Name ="Name2"} };
RadGrid1.DataSource = data;
}
protected void RadGrid1_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
{
GridDataItem parentItem = e.DetailTableView.ParentItem as GridDataItem;
if (e.DetailTableView.Name == "Images")
{
dynamic data = new[] {
new { ID = 11, Name ="Name11"},
new { ID = 12, Name ="Name12"} };
e.DetailTableView.DataSource = data;
}
else if (e.DetailTableView.Name == "Something")
{
dynamic data = new[] {
new { ID = 111, Name ="Name111"},
new { ID = 112, Name ="Name112"} };
e.DetailTableView.DataSource = data;
}
}
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == "ExpandSomething")
{
GridDataItem item = e.Item as GridDataItem;
item.Expanded = true;
if (e.Item.HasChildItems)
{
item.ChildItem.NestedTableViews[0].Visible = false;
item.ChildItem.NestedTableViews[1].Visible = true;
}
}
else if (e.CommandName == "ExpandSomethingElse")
{
GridDataItem item = e.Item as GridDataItem;
item.Expanded = true;
if (e.Item.HasChildItems)
{
item.ChildItem.NestedTableViews[0].Visible = true;
item.ChildItem.NestedTableViews[1].Visible = false;
}
}
}
如果有任何疑虑,请告诉我。