Rad Gird 嵌套子模板网格不显示
Rad Gird Nested Child Template Grid Don't Show
我想在 Asp:place holder 中绑定 radgid,它工作得很好,但我想扩展绑定的 radgrid,它不扩展只是旋转 ajaxmanager。
Home.ascx
<telerik:RadGrid ID="rgItemHistory" runat="server" AllowPaging="false" AutoGenerateColumns="false" OnPreRender="rgItemHistory_PreRender" OnItemCommand="rgItemHistory_ItemCommand" OnNeedDataSource="rgItemHistory_NeedDataSource" >
<MasterTableView DataKeyNames="ItemID,HistoryDate" ExpandCollapseColumn-HeaderStyle-Width="1px">
<Columns>
<telerik:GridBoundColumn DataField="ItemID" HeaderText="ItemID" HeaderStyle-Width="10%" UniqueName="ItemID" Visible="false" />
<telerik:GridBoundColumn DataField="HistoryDate" HeaderText="HistoryDate" UniqueName="HistoryDate" >
<HeaderStyle HorizontalAlign="Center" Width="10%" />
<ItemStyle HorizontalAlign="Center" Width="10%" VerticalAlign="Top" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Cost" HeaderText="Cost" UniqueName="Cost" >
<HeaderStyle HorizontalAlign="Center" Width="10%" />
<ItemStyle HorizontalAlign="Center" Width="10%" VerticalAlign="Top" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="MfgrPartListSale" HeaderText="MfgrPartListSale" UniqueName="MfgrPartListSale" >
<HeaderStyle HorizontalAlign="Center" Width="10%" />
<ItemStyle HorizontalAlign="Center" Width="10%" VerticalAlign="Top" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="MfgrPartWSale" HeaderText="MfgrPartWSale" UniqueName="MfgrPartWSale" >
<HeaderStyle HorizontalAlign="Center" Width="10%" />
<ItemStyle HorizontalAlign="Center" Width="10%" VerticalAlign="Top" />
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn AllowFiltering="false">
<HeaderStyle HorizontalAlign="Left" Width="60%" />
<ItemStyle HorizontalAlign="Left" Width="60%" VerticalAlign="Top" />
</telerik:GridTemplateColumn>
</Columns>
<NestedViewTemplate >
<asp:PlaceHolder runat="server" ID="pnlBOMHistory">
<%--<uctrl:BOMHistory id="ucBOMHistory" runat="server" ></uctrl:BOMHistory>--%>
</asp:PlaceHolder>
</NestedViewTemplate>
</MasterTableView>
<ClientSettings>
</ClientSettings>
</telerik:RadGrid>
Home.ascx.cs
protected void rgItemHistory_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
if (Convert.ToInt32(ViewState["ItemID"]) >= 0)
{
Item objItem = new Item();
objItem.ItemId = Id;
rgItemHistory.DataSource = objItem.GetItemHistory();
objItem = null;
}
}
protected void rgItemHistory_PreRender(object sender, EventArgs e)
{
foreach (GridDataItem item in rgItemHistory.MasterTableView.Items)
{
if (item.Expanded)
{
string userControlName = "~/BOMHistory.ascx";
Control userControl = Page.LoadControl(userControlName);
PlaceHolder panel = (PlaceHolder)item.ChildItem.FindControl("pnlBOMHistory");
//Panel panel = (Panel)item.ChildItem.FindControl("pnlBOMHistory");
UCtrlBOMHistory uc = userControl as UCtrlBOMHistory;
uc.Id = Convert.ToInt32(item.GetDataKeyValue("ItemID"));
uc.HistoryDate = item.GetDataKeyValue("HistoryDate").ToString();
uc.Type = Type;//"FinishGood";
panel.Controls.Add(userControl);
}
}
}
Home1.axcs
<tr>
<td>
</td>
<td>
<asp:PlaceHolder ID="phMain" runat="server"></asp:PlaceHolder>
</td>
<td>
</td>
</tr>
Home1.ascx.cs
public void DefineStructure()
{
RadGrid grd = new RadGrid();
grd.ID = "rgrdMain";
grd.MasterTableView.Columns.Clear();
grd.MasterTableView.DetailTables.Clear();
grd.EnableLinqExpressions = false;
grd.PagerStyle.Mode = GridPagerMode.NextPrevNumericAndAdvanced;
//grd.PageSize = 20;
grd.PageSize = 999;
//grd.ClientSettings.Scrolling.AllowScroll = true;
//grd.ClientSettings.Scrolling.UseStaticHeaders = true;
//grd.ClientSettings.Scrolling.SaveScrollPosition = true;
//grd.ClientSettings.Scrolling.ScrollHeight = 500;
//grd.ClientSettings.ClientEvents.OnGridCreated = "GridCreated";
// Added by Herin
grd.ShowFooter = true;
grd.FooterStyle.CssClass = "footerBackColor";
if (Request.Url.AbsoluteUri.Contains("BillOfMaterialListing.aspx"))
{
grd.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None;
//grd.MasterTableView.CommandItemTemplate = new BOMCommandItemTemplate();
}
else
{
grd.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Bottom;
grd.MasterTableView.CommandItemTemplate = new BOMHistoryCommandItemTemplate();
}
grd.ClientSettings.ClientEvents.OnHierarchyExpanded = "function() {if(window.parent){if(window.parent.resizeIFrame){window.parent.resizeIFrame();}}}";
grd.ClientSettings.ClientEvents.OnHierarchyCollapsed = "function() {if(window.parent){if(window.parent.resizeIFrame){window.parent.resizeIFrame();}}}";
grd.ClientSettings.Selecting.AllowRowSelect = true;
//FinishedGood/SubAssembly/Component/PurchasedItem/Asset Master
//if (Convert.ToString(ViewState["Type"]).Trim() == "FinishedGood" || Convert.ToString(ViewState["Type"]).Trim() == "SubAssembly" || Convert.ToString(ViewState["Type"]).Trim() == "Component" || Convert.ToString(ViewState["Type"]).Trim() == "PurchasedItem" || Convert.ToString(ViewState["Type"]).Trim() == "Asset")
if (Type == "FinishedGood" || Type == "SubAssembly" || Type == "Component" || Type == "PurchasedItem" || Type == "Asset")
{
grd.NeedDataSource += new GridNeedDataSourceEventHandler(rgrdItem_NeedDataSource);
grd.ItemDataBound += new GridItemEventHandler(rgrdItem_ItemDataBound);
grd.ItemCommand += new GridCommandEventHandler(rgrdItem_ItemCommand);
grd.PreRender += new EventHandler(rgrdItem_PreRender)
//Top Level Variant Grid
string[] varDataKeys = new string[] { "ItemID", "HistoryDate" };
List<BOMHistoryGridColumn> lstVarCols = new List<BOMHistoryGridColumn>();
lstVarCols.Add(new BOMHistoryGridColumn("ItemID", "ItemID", "Bound", Unit.Percentage(8)));
lstVarCols.Add(new BOMHistoryGridColumn("HistoryDate", "HistoryDate", "Bound", Unit.Percentage(38)));
lstVarCols.Add(new BOMHistoryGridColumn("Cost", "Cost", "Bound", Unit.Percentage(12)));
lstVarCols.Add(new BOMHistoryGridColumn("MfgrPartListSale", "MfgrPartListSale", "Bound", Unit.Percentage(8)));
lstVarCols.Add(new BOMHistoryGridColumn("MfgrPartWSale", "MfgrPartWSale", "Bound", Unit.Percentage(8)));
SetTopLevelGrid(grd, "ItemHistory", varDataKeys, lstVarCols, "", "");
//Item Table
string[] dataKeys = new string[] { "BOMId", "Item.ItemTypeId", "ParentItemId", "ChildItemId" };
List<BOMHistoryGridColumn> lstItemCols = new List<BOMHistoryGridColumn>();
if (Request.Url.AbsoluteUri.Contains("BillOfMaterialListing.aspx"))
lstItemCols.Add(new BOMHistoryGridColumn("ChildItemId", "ID", "Bound", Unit.Percentage(5)));
else
lstItemCols.Add(new BOMHistoryGridColumn("ChildItemId", "ID", "LinkTemplate", Unit.Percentage(5)));
lstItemCols.Add(new BOMHistoryGridColumn("BOMId", "BOM ID", "Bound", Unit.Percentage(5)));
lstItemCols.Add(new BOMHistoryGridColumn("Item.AltNbr", "Alt Nbr", "Bound", Unit.Percentage(6)));
lstItemCols.Add(new BOMHistoryGridColumn("Item.ItemType", "Item Type", "Bound", Unit.Percentage(7)));
lstItemCols.Add(new BOMHistoryGridColumn("Item.Description", "Item Name", "Bound", Unit.Percentage(7)));
lstItemCols.Add(new BOMHistoryGridColumn("Notes", "Notes", "Bound", Unit.Percentage(7)));
lstItemCols.Add(new BOMHistoryGridColumn("ParentStockingUOMQty", "Qty Used in Parent's Stocking UOM", "Bound", Unit.Percentage(6), "{0:F4}"));
lstItemCols.Add(new BOMHistoryGridColumn("ParentStockingUOMExtCost", "Parent Stocking UOM Ext Cost", "Bound", Unit.Percentage(5), "{0:C4}"));
lstItemCols.Add(new BOMHistoryGridColumn("FirstUOMCost", "First UOM Cost", "Bound", Unit.Percentage(5), "{0:F4}"));
lstItemCols.Add(new BOMHistoryGridColumn("TotalQty", "First UOM Qty", "Bound", Unit.Percentage(5), "{0:F4}"));
lstItemCols.Add(new BOMHistoryGridColumn("FirstUOM", "First UOM", "Bound", Unit.Percentage(5), "{0:C4}"));
lstItemCols.Add(new BOMHistoryGridColumn("UsageCost", "Usage UOM Cost", "Bound", Unit.Percentage(5), "{0:C4}"));
lstItemCols.Add(new BOMHistoryGridColumn("UsageQty", "Usage UOM Qty", "Bound", Unit.Percentage(5), "{0:F4}"));
lstItemCols.Add(new BOMHistoryGridColumn("UsageScrap", "Usage Scrap", "Bound", Unit.Percentage(5), "{0:F4}"));
lstItemCols.Add(new BOMHistoryGridColumn("UsageUOM", "Usage UOM", "Bound", Unit.Percentage(5)));
lstItemCols.Add(new BOMHistoryGridColumn("UsageExtCost", "Usage UOM Ext Cost", "Bound", Unit.Percentage(5), "{0:C4}"));
lstItemCols.Add(new BOMHistoryGridColumn("StockingCost", "Stocking UOM Cost", "Bound", Unit.Percentage(5), "{0:C4}"));
lstItemCols.Add(new BOMHistoryGridColumn("StockingQty", "Stocking UOM Qty", "Bound", Unit.Percentage(5), "{0:F4}"));
lstItemCols.Add(new BOMHistoryGridColumn("StockingUOM", "Stocking UOM", "Bound", Unit.Percentage(5)));
lstItemCols.Add(new BOMHistoryGridColumn("QtyOH", "Qty O/H", "Bound", Unit.Percentage(5)));
//Unit.Pixel(100)
if (Request.Url.AbsoluteUri.Contains("BillOfMaterialListing.aspx"))
lstItemCols.Add(new BOMHistoryGridColumn("RoutingId", "Routing ID", "Bound", Unit.Percentage(4)));
else
lstItemCols.Add(new BOMHistoryGridColumn("RoutingId", "Rout ID", "LinkTemplate", Unit.Percentage(4)));
lstItemCols.Add(new BOMHistoryGridColumn("PatternNbr", "Pattern Nbr", "Bound", Unit.Percentage(6)));
lstItemCols.Add(new BOMHistoryGridColumn("OperationTemplate", "", "OperationTemplate", Unit.Percentage(3)));
//if (Convert.ToString(ViewState["Type"]).Trim() != "Asset")
if (Type != "Asset")
{
lstItemCols.Add(new BOMHistoryGridColumn("Past52Weeks", "Past 52 Wks", "Bound", Unit.Percentage(5)));
lstItemCols.Add(new BOMHistoryGridColumn("NbrOfCust", "Nbr of Cust", "Bound", Unit.Percentage(4)));
}
//if (Convert.ToString(ViewState["Type"]).Trim() == "FinishedGood")
if (Type == "FinishedGood")
lstItemCols.Add(new BOMHistoryGridColumn("CheckBoxTemplatePrimaryMaterial", "Primary Material", "CheckBoxColumn", Unit.Percentage(6)));
//if (Convert.ToString(ViewState["Type"]).Trim() == "FinishedGood")
if (Type == "FinishedGood")
lstItemCols.Add(new BOMHistoryGridColumn("CheckBoxTemplatePrimary", "Primary Packaging", "CheckBoxColumn", Unit.Percentage(6)));
lstItemCols.Add(new BOMHistoryGridColumn("IsBOMChanged", "", "Bound", Unit.Percentage(5)));
SetTopLevelGrid(grd, "Item", dataKeys, lstItemCols, "ParentItemId", "ChildItemId");
}
phMain.Controls.Add(grd);
//grd.Rebind();
}
private RadGrid SetTopLevelGrid(RadGrid grid, string tblName, string[] dataKeys, List<BOMHistoryGridColumn> columns, string selfHierarchyParentId, string selfHierarchyChildId)
{
grid.MasterTableView.DataKeyNames = dataKeys;
grid.MasterTableView.EnableColumnsViewState = false;
grid.Width = Unit.Percentage(100);
//grid.PageSize = 20;
grid.PageSize = 999;
grid.AllowPaging = true;
grid.AllowSorting = true;
grid.PagerStyle.Mode = GridPagerMode.NextPrevNumericAndAdvanced;
grid.AutoGenerateColumns = false;
grid.ShowStatusBar = false;
//grid.MasterTableView.PageSize = 20;
grid.MasterTableView.PageSize = 999;
grid.MasterTableView.Name = tblName;
grid.ClientSettings.Selecting.AllowRowSelect = true;
grid.ClientSettings.Scrolling.AllowScroll = true;
grid.ClientSettings.Scrolling.UseStaticHeaders = true;
grid.ClientSettings.Scrolling.SaveScrollPosition = true;
grid.ClientSettings.Scrolling.ScrollHeight = 500;
grid.ClientSettings.ClientEvents.OnGridCreated = "GridCreated";
GridColumnGroup colGrop = new GridColumnGroup();
colGrop.HeaderText = "Child First UOM";
colGrop.Name = "ChildFirstUOM";
colGrop.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
colGrop.HeaderStyle.CssClass = "firstUOM";
grid.MasterTableView.ColumnGroups.Add(colGrop);
GridColumnGroup colGrop1 = new GridColumnGroup();
colGrop1.HeaderText = "Child Usage";
colGrop1.Name = "ChildUsage";
colGrop1.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
colGrop1.HeaderStyle.CssClass = "specificHeader";
grid.MasterTableView.ColumnGroups.Add(colGrop1);
GridColumnGroup colGrop2 = new GridColumnGroup();
colGrop2.HeaderText = "Child Stocking UOM";
colGrop2.Name = "ChildStockingUOM";
colGrop2.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
colGrop2.HeaderStyle.CssClass = "stockingCost";
grid.MasterTableView.ColumnGroups.Add(colGrop2);
if (!string.IsNullOrEmpty(selfHierarchyChildId) && !string.IsNullOrEmpty(selfHierarchyParentId))
{
grid.MasterTableView.HierarchyLoadMode = GridChildLoadMode.ServerOnDemand;
grid.MasterTableView.SelfHierarchySettings.KeyName = selfHierarchyChildId;
grid.MasterTableView.SelfHierarchySettings.ParentKeyName = selfHierarchyParentId;
grid.MasterTableView.FilterExpression = selfHierarchyParentId + " = 0";
}
AddColumnsToGridTableView(grid.MasterTableView, columns);
return grid;
}
protected void rgrdMain_PreRender(object sender, EventArgs e)
{
//if (!IsPostBack)
//{
// GridTableView gtv = (sender as RadGrid).MasterTableView;
// if (gtv != null)
// {
// if (gtv.Items.Count > 0)
// gtv.Items[0].Expanded = true;
// }
//}
HideOperationsColumnForChilds((sender as RadGrid).MasterTableView);
}
protected void rgrdMain_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
RadGrid rgrdMain = source as RadGrid;
//if (Convert.ToInt32(ViewState["ID"]) > 0)
//{
// if (Convert.ToString(ViewState["Type"]).Trim() == "Product")
// {
// Product objProd = new Product();
// objProd.ProductId = Convert.ToInt32(ViewState["ID"]);
// rgrdMain.DataSource = objProd.GetProductVariants();
// }
// if (Convert.ToString(ViewState["Type"]).Trim() == "Variant")
// {
// Variant objVar = new Variant();
// objVar.VariantId = Convert.ToInt32(ViewState["ID"]);
// rgrdMain.DataSource = objVar.GetVariantFinishedGoods();
// }
//}
if (Convert.ToInt32(ViewState["ItemID"]) >= 0)
{
Item objItem = new Item();
objItem.ItemId = Id;
rgrdMain.DataSource = objItem.GetItemHistory();
objItem = null;
}
if (rgrdMain.DataSource != null)
ramMain.AjaxSettings.AddAjaxSetting(rgrdMain, rgrdMain, this.Page.FindControl("ralpMain") as RadAjaxLoadingPanel);
}
protected void rgrdMain_ItemDataBound(object sender, GridItemEventArgs e)
{
//For 100% width
e.Item.OwnerTableView.Width = new Unit(100, UnitType.Percentage);
if (e.Item.ItemType == GridItemType.CommandItem)
{
//Image imgAssignNew = e.Item.FindControl("imgAssignNew") as Image;
//LinkButton lnkbtnAssignNew = e.Item.FindControl("lnkbtnAssignNew") as LinkButton;
//Image imgCloneBOM = e.Item.FindControl("imgCloneBOM") as Image;
//LinkButton lnkbtnCloneBOM = e.Item.FindControl("lnkbtnCloneBOM") as LinkButton;
//imgCloneBOM.Visible = false;
//lnkbtnCloneBOM.Visible = false;
//Hide CommandItem for Child Tables
if (e.Item.OwnerTableView.ParentItem != null)
e.Item.Visible = false;
//switch (Convert.ToString(ViewState["Type"]).Trim())
switch (Type)
{
case "Product":
//imgAssignNew.Attributes.Add("OnClick", "return ShowSearch('Assign Product - BOM'," + Convert.ToString(ViewState["ID"]).Trim() + ", 'Product'," + Convert.ToString(0).Trim() + ", 'BOM'," + Convert.ToString(0).Trim() + ");");
//lnkbtnAssignNew.Attributes.Add("OnClick", "return ShowSearch('Assign Product - BOM'," + Convert.ToString(ViewState["ID"]).Trim() + ", 'Product'," + Convert.ToString(0).Trim() + ", 'BOM'," + Convert.ToString(0).Trim() + ");");
break;
case "Variant":
//imgAssignNew.Attributes.Add("OnClick", "return ShowSearch('Assign Variant - BOM'," + Convert.ToString(ViewState["ID"]).Trim() + ", 'Variant'," + Convert.ToString(0).Trim() + ", 'BOM'," + Convert.ToString(0).Trim() + ");");
//lnkbtnAssignNew.Attributes.Add("OnClick", "return ShowSearch('Assign Variant - BOM'," + Convert.ToString(ViewState["ID"]).Trim() + ", 'Variant'," + Convert.ToString(0).Trim() + ", 'BOM'," + Convert.ToString(0).Trim() + ");");
break;
default:
break;
}
}
if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
{
RadToolTip rttHistory = e.Item.FindControl("rttHistory") as RadToolTip;
//ImageButton imgbtnEdit = e.Item.FindControl("imgbtnEdit") as ImageButton;
ImageButton imgbtnHistory = e.Item.FindControl("imgbtnHistory") as ImageButton;
//ImageButton imgbtnDelete = e.Item.FindControl("imgbtnDelete") as ImageButton;
if (e.Item.OwnerTableView.Name == "Variant")
{
Variant objVar = e.Item.DataItem as Variant;
LinkButton lnkbtnVariantNo = e.Item.FindControl("lnkbtnVariantNo") as LinkButton;
//imgbtnEdit.Visible = true;
lnkbtnVariantNo.Text = objVar.VariantNo;
rttHistory.Text = GeneralData.GetHistoryTooltipText(objVar.Deleted, objVar.CreatedOn, objVar.CreatedBy, objVar.LastModifiedOn, objVar.LastModifiedBy);
//imgbtnEdit.Attributes.Add("OnClick", "return EditBOMVariant(" + objVar.VariantId.ToString() + "); return false;");
lnkbtnVariantNo.Attributes.Add("OnClick", "if(window.parent){window.parent.openMasterInNewWindow('var','" + objVar.VariantId.ToString() + "');} return false;");
//imgbtnDelete.Attributes.Add("OnClick", "return confirm('Are you sure to delete this record?');");
}
if (e.Item.OwnerTableView.Name == "FinishedGood")
{
FinishedGood objFg = e.Item.DataItem as FinishedGood;
LinkButton lnkbtnSize = e.Item.FindControl("lnkbtnSize") as LinkButton;
LinkButton lnkbtnRoutingMaster = e.Item.FindControl("lnkbtnRoutingMaster") as LinkButton;
//imgbtnEdit.Visible = false;
lnkbtnSize.Text = objFg.Size;
if (lnkbtnRoutingMaster != null)
{
lnkbtnRoutingMaster.Text = objFg.RoutingMaster.ToString();
lnkbtnRoutingMaster.Visible = true;
if (objFg.RoutingMaster > 0)
lnkbtnRoutingMaster.Attributes.Add("OnClick", "if(window.parent){window.parent.openMasterInNewWindow('rout','" + objFg.RoutingMaster.ToString() + "');} return false;");
else
lnkbtnRoutingMaster.Visible = false;
}
rttHistory.Text = GeneralData.GetHistoryTooltipText(objFg.Deleted, objFg.CreatedOn, objFg.CreatedBy, objFg.LastModifiedOn, objFg.LastModifiedBy);
lnkbtnSize.Attributes.Add("OnClick", "if(window.parent){window.parent.openMasterInNewWindow('fgood','" + objFg.FinishedGoodId.ToString() + "');} return false;");
//imgbtnDelete.Attributes.Add("OnClick", "return confirm('Are you sure to delete this record?');");
}
}
}
protected void rgrdMain_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.ExpandCollapseCommandName)
{
if (!e.Item.Expanded)
{
//Only for Item grid in NeadtedTemplet
if (e.Item.OwnerTableView.Name == "Item")
{
//Rebind Child Item Grid on Expand
RadGrid grid = ((GridDataItem)e.Item).ChildItem.FindControl("rgrdItem") as RadGrid;
grid.Rebind();
}
}
RadAjaxManager.GetCurrent(this.Page).ResponseScripts.Add("if(window.parent){if(window.parent.resizeIFrame){window.parent.resizeIFrame();}}");
}
}
我的代码哪里有问题请帮忙!!!
我猜想在加载用户控件时出现服务器错误。在这里设置一个断点,看看 userControl 是否是你所期望的。 panel.Controls.Add(用户控件); AJAX 的棘手之处在于您可能会遇到服务器错误,并且 UI 中不会有任何指示。
我想在 Asp:place holder 中绑定 radgid,它工作得很好,但我想扩展绑定的 radgrid,它不扩展只是旋转 ajaxmanager。
Home.ascx
<telerik:RadGrid ID="rgItemHistory" runat="server" AllowPaging="false" AutoGenerateColumns="false" OnPreRender="rgItemHistory_PreRender" OnItemCommand="rgItemHistory_ItemCommand" OnNeedDataSource="rgItemHistory_NeedDataSource" >
<MasterTableView DataKeyNames="ItemID,HistoryDate" ExpandCollapseColumn-HeaderStyle-Width="1px">
<Columns>
<telerik:GridBoundColumn DataField="ItemID" HeaderText="ItemID" HeaderStyle-Width="10%" UniqueName="ItemID" Visible="false" />
<telerik:GridBoundColumn DataField="HistoryDate" HeaderText="HistoryDate" UniqueName="HistoryDate" >
<HeaderStyle HorizontalAlign="Center" Width="10%" />
<ItemStyle HorizontalAlign="Center" Width="10%" VerticalAlign="Top" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Cost" HeaderText="Cost" UniqueName="Cost" >
<HeaderStyle HorizontalAlign="Center" Width="10%" />
<ItemStyle HorizontalAlign="Center" Width="10%" VerticalAlign="Top" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="MfgrPartListSale" HeaderText="MfgrPartListSale" UniqueName="MfgrPartListSale" >
<HeaderStyle HorizontalAlign="Center" Width="10%" />
<ItemStyle HorizontalAlign="Center" Width="10%" VerticalAlign="Top" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="MfgrPartWSale" HeaderText="MfgrPartWSale" UniqueName="MfgrPartWSale" >
<HeaderStyle HorizontalAlign="Center" Width="10%" />
<ItemStyle HorizontalAlign="Center" Width="10%" VerticalAlign="Top" />
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn AllowFiltering="false">
<HeaderStyle HorizontalAlign="Left" Width="60%" />
<ItemStyle HorizontalAlign="Left" Width="60%" VerticalAlign="Top" />
</telerik:GridTemplateColumn>
</Columns>
<NestedViewTemplate >
<asp:PlaceHolder runat="server" ID="pnlBOMHistory">
<%--<uctrl:BOMHistory id="ucBOMHistory" runat="server" ></uctrl:BOMHistory>--%>
</asp:PlaceHolder>
</NestedViewTemplate>
</MasterTableView>
<ClientSettings>
</ClientSettings>
</telerik:RadGrid>
Home.ascx.cs
protected void rgItemHistory_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
if (Convert.ToInt32(ViewState["ItemID"]) >= 0)
{
Item objItem = new Item();
objItem.ItemId = Id;
rgItemHistory.DataSource = objItem.GetItemHistory();
objItem = null;
}
}
protected void rgItemHistory_PreRender(object sender, EventArgs e)
{
foreach (GridDataItem item in rgItemHistory.MasterTableView.Items)
{
if (item.Expanded)
{
string userControlName = "~/BOMHistory.ascx";
Control userControl = Page.LoadControl(userControlName);
PlaceHolder panel = (PlaceHolder)item.ChildItem.FindControl("pnlBOMHistory");
//Panel panel = (Panel)item.ChildItem.FindControl("pnlBOMHistory");
UCtrlBOMHistory uc = userControl as UCtrlBOMHistory;
uc.Id = Convert.ToInt32(item.GetDataKeyValue("ItemID"));
uc.HistoryDate = item.GetDataKeyValue("HistoryDate").ToString();
uc.Type = Type;//"FinishGood";
panel.Controls.Add(userControl);
}
}
}
Home1.axcs
<tr>
<td>
</td>
<td>
<asp:PlaceHolder ID="phMain" runat="server"></asp:PlaceHolder>
</td>
<td>
</td>
</tr>
Home1.ascx.cs
public void DefineStructure()
{
RadGrid grd = new RadGrid();
grd.ID = "rgrdMain";
grd.MasterTableView.Columns.Clear();
grd.MasterTableView.DetailTables.Clear();
grd.EnableLinqExpressions = false;
grd.PagerStyle.Mode = GridPagerMode.NextPrevNumericAndAdvanced;
//grd.PageSize = 20;
grd.PageSize = 999;
//grd.ClientSettings.Scrolling.AllowScroll = true;
//grd.ClientSettings.Scrolling.UseStaticHeaders = true;
//grd.ClientSettings.Scrolling.SaveScrollPosition = true;
//grd.ClientSettings.Scrolling.ScrollHeight = 500;
//grd.ClientSettings.ClientEvents.OnGridCreated = "GridCreated";
// Added by Herin
grd.ShowFooter = true;
grd.FooterStyle.CssClass = "footerBackColor";
if (Request.Url.AbsoluteUri.Contains("BillOfMaterialListing.aspx"))
{
grd.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None;
//grd.MasterTableView.CommandItemTemplate = new BOMCommandItemTemplate();
}
else
{
grd.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Bottom;
grd.MasterTableView.CommandItemTemplate = new BOMHistoryCommandItemTemplate();
}
grd.ClientSettings.ClientEvents.OnHierarchyExpanded = "function() {if(window.parent){if(window.parent.resizeIFrame){window.parent.resizeIFrame();}}}";
grd.ClientSettings.ClientEvents.OnHierarchyCollapsed = "function() {if(window.parent){if(window.parent.resizeIFrame){window.parent.resizeIFrame();}}}";
grd.ClientSettings.Selecting.AllowRowSelect = true;
//FinishedGood/SubAssembly/Component/PurchasedItem/Asset Master
//if (Convert.ToString(ViewState["Type"]).Trim() == "FinishedGood" || Convert.ToString(ViewState["Type"]).Trim() == "SubAssembly" || Convert.ToString(ViewState["Type"]).Trim() == "Component" || Convert.ToString(ViewState["Type"]).Trim() == "PurchasedItem" || Convert.ToString(ViewState["Type"]).Trim() == "Asset")
if (Type == "FinishedGood" || Type == "SubAssembly" || Type == "Component" || Type == "PurchasedItem" || Type == "Asset")
{
grd.NeedDataSource += new GridNeedDataSourceEventHandler(rgrdItem_NeedDataSource);
grd.ItemDataBound += new GridItemEventHandler(rgrdItem_ItemDataBound);
grd.ItemCommand += new GridCommandEventHandler(rgrdItem_ItemCommand);
grd.PreRender += new EventHandler(rgrdItem_PreRender)
//Top Level Variant Grid
string[] varDataKeys = new string[] { "ItemID", "HistoryDate" };
List<BOMHistoryGridColumn> lstVarCols = new List<BOMHistoryGridColumn>();
lstVarCols.Add(new BOMHistoryGridColumn("ItemID", "ItemID", "Bound", Unit.Percentage(8)));
lstVarCols.Add(new BOMHistoryGridColumn("HistoryDate", "HistoryDate", "Bound", Unit.Percentage(38)));
lstVarCols.Add(new BOMHistoryGridColumn("Cost", "Cost", "Bound", Unit.Percentage(12)));
lstVarCols.Add(new BOMHistoryGridColumn("MfgrPartListSale", "MfgrPartListSale", "Bound", Unit.Percentage(8)));
lstVarCols.Add(new BOMHistoryGridColumn("MfgrPartWSale", "MfgrPartWSale", "Bound", Unit.Percentage(8)));
SetTopLevelGrid(grd, "ItemHistory", varDataKeys, lstVarCols, "", "");
//Item Table
string[] dataKeys = new string[] { "BOMId", "Item.ItemTypeId", "ParentItemId", "ChildItemId" };
List<BOMHistoryGridColumn> lstItemCols = new List<BOMHistoryGridColumn>();
if (Request.Url.AbsoluteUri.Contains("BillOfMaterialListing.aspx"))
lstItemCols.Add(new BOMHistoryGridColumn("ChildItemId", "ID", "Bound", Unit.Percentage(5)));
else
lstItemCols.Add(new BOMHistoryGridColumn("ChildItemId", "ID", "LinkTemplate", Unit.Percentage(5)));
lstItemCols.Add(new BOMHistoryGridColumn("BOMId", "BOM ID", "Bound", Unit.Percentage(5)));
lstItemCols.Add(new BOMHistoryGridColumn("Item.AltNbr", "Alt Nbr", "Bound", Unit.Percentage(6)));
lstItemCols.Add(new BOMHistoryGridColumn("Item.ItemType", "Item Type", "Bound", Unit.Percentage(7)));
lstItemCols.Add(new BOMHistoryGridColumn("Item.Description", "Item Name", "Bound", Unit.Percentage(7)));
lstItemCols.Add(new BOMHistoryGridColumn("Notes", "Notes", "Bound", Unit.Percentage(7)));
lstItemCols.Add(new BOMHistoryGridColumn("ParentStockingUOMQty", "Qty Used in Parent's Stocking UOM", "Bound", Unit.Percentage(6), "{0:F4}"));
lstItemCols.Add(new BOMHistoryGridColumn("ParentStockingUOMExtCost", "Parent Stocking UOM Ext Cost", "Bound", Unit.Percentage(5), "{0:C4}"));
lstItemCols.Add(new BOMHistoryGridColumn("FirstUOMCost", "First UOM Cost", "Bound", Unit.Percentage(5), "{0:F4}"));
lstItemCols.Add(new BOMHistoryGridColumn("TotalQty", "First UOM Qty", "Bound", Unit.Percentage(5), "{0:F4}"));
lstItemCols.Add(new BOMHistoryGridColumn("FirstUOM", "First UOM", "Bound", Unit.Percentage(5), "{0:C4}"));
lstItemCols.Add(new BOMHistoryGridColumn("UsageCost", "Usage UOM Cost", "Bound", Unit.Percentage(5), "{0:C4}"));
lstItemCols.Add(new BOMHistoryGridColumn("UsageQty", "Usage UOM Qty", "Bound", Unit.Percentage(5), "{0:F4}"));
lstItemCols.Add(new BOMHistoryGridColumn("UsageScrap", "Usage Scrap", "Bound", Unit.Percentage(5), "{0:F4}"));
lstItemCols.Add(new BOMHistoryGridColumn("UsageUOM", "Usage UOM", "Bound", Unit.Percentage(5)));
lstItemCols.Add(new BOMHistoryGridColumn("UsageExtCost", "Usage UOM Ext Cost", "Bound", Unit.Percentage(5), "{0:C4}"));
lstItemCols.Add(new BOMHistoryGridColumn("StockingCost", "Stocking UOM Cost", "Bound", Unit.Percentage(5), "{0:C4}"));
lstItemCols.Add(new BOMHistoryGridColumn("StockingQty", "Stocking UOM Qty", "Bound", Unit.Percentage(5), "{0:F4}"));
lstItemCols.Add(new BOMHistoryGridColumn("StockingUOM", "Stocking UOM", "Bound", Unit.Percentage(5)));
lstItemCols.Add(new BOMHistoryGridColumn("QtyOH", "Qty O/H", "Bound", Unit.Percentage(5)));
//Unit.Pixel(100)
if (Request.Url.AbsoluteUri.Contains("BillOfMaterialListing.aspx"))
lstItemCols.Add(new BOMHistoryGridColumn("RoutingId", "Routing ID", "Bound", Unit.Percentage(4)));
else
lstItemCols.Add(new BOMHistoryGridColumn("RoutingId", "Rout ID", "LinkTemplate", Unit.Percentage(4)));
lstItemCols.Add(new BOMHistoryGridColumn("PatternNbr", "Pattern Nbr", "Bound", Unit.Percentage(6)));
lstItemCols.Add(new BOMHistoryGridColumn("OperationTemplate", "", "OperationTemplate", Unit.Percentage(3)));
//if (Convert.ToString(ViewState["Type"]).Trim() != "Asset")
if (Type != "Asset")
{
lstItemCols.Add(new BOMHistoryGridColumn("Past52Weeks", "Past 52 Wks", "Bound", Unit.Percentage(5)));
lstItemCols.Add(new BOMHistoryGridColumn("NbrOfCust", "Nbr of Cust", "Bound", Unit.Percentage(4)));
}
//if (Convert.ToString(ViewState["Type"]).Trim() == "FinishedGood")
if (Type == "FinishedGood")
lstItemCols.Add(new BOMHistoryGridColumn("CheckBoxTemplatePrimaryMaterial", "Primary Material", "CheckBoxColumn", Unit.Percentage(6)));
//if (Convert.ToString(ViewState["Type"]).Trim() == "FinishedGood")
if (Type == "FinishedGood")
lstItemCols.Add(new BOMHistoryGridColumn("CheckBoxTemplatePrimary", "Primary Packaging", "CheckBoxColumn", Unit.Percentage(6)));
lstItemCols.Add(new BOMHistoryGridColumn("IsBOMChanged", "", "Bound", Unit.Percentage(5)));
SetTopLevelGrid(grd, "Item", dataKeys, lstItemCols, "ParentItemId", "ChildItemId");
}
phMain.Controls.Add(grd);
//grd.Rebind();
}
private RadGrid SetTopLevelGrid(RadGrid grid, string tblName, string[] dataKeys, List<BOMHistoryGridColumn> columns, string selfHierarchyParentId, string selfHierarchyChildId)
{
grid.MasterTableView.DataKeyNames = dataKeys;
grid.MasterTableView.EnableColumnsViewState = false;
grid.Width = Unit.Percentage(100);
//grid.PageSize = 20;
grid.PageSize = 999;
grid.AllowPaging = true;
grid.AllowSorting = true;
grid.PagerStyle.Mode = GridPagerMode.NextPrevNumericAndAdvanced;
grid.AutoGenerateColumns = false;
grid.ShowStatusBar = false;
//grid.MasterTableView.PageSize = 20;
grid.MasterTableView.PageSize = 999;
grid.MasterTableView.Name = tblName;
grid.ClientSettings.Selecting.AllowRowSelect = true;
grid.ClientSettings.Scrolling.AllowScroll = true;
grid.ClientSettings.Scrolling.UseStaticHeaders = true;
grid.ClientSettings.Scrolling.SaveScrollPosition = true;
grid.ClientSettings.Scrolling.ScrollHeight = 500;
grid.ClientSettings.ClientEvents.OnGridCreated = "GridCreated";
GridColumnGroup colGrop = new GridColumnGroup();
colGrop.HeaderText = "Child First UOM";
colGrop.Name = "ChildFirstUOM";
colGrop.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
colGrop.HeaderStyle.CssClass = "firstUOM";
grid.MasterTableView.ColumnGroups.Add(colGrop);
GridColumnGroup colGrop1 = new GridColumnGroup();
colGrop1.HeaderText = "Child Usage";
colGrop1.Name = "ChildUsage";
colGrop1.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
colGrop1.HeaderStyle.CssClass = "specificHeader";
grid.MasterTableView.ColumnGroups.Add(colGrop1);
GridColumnGroup colGrop2 = new GridColumnGroup();
colGrop2.HeaderText = "Child Stocking UOM";
colGrop2.Name = "ChildStockingUOM";
colGrop2.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
colGrop2.HeaderStyle.CssClass = "stockingCost";
grid.MasterTableView.ColumnGroups.Add(colGrop2);
if (!string.IsNullOrEmpty(selfHierarchyChildId) && !string.IsNullOrEmpty(selfHierarchyParentId))
{
grid.MasterTableView.HierarchyLoadMode = GridChildLoadMode.ServerOnDemand;
grid.MasterTableView.SelfHierarchySettings.KeyName = selfHierarchyChildId;
grid.MasterTableView.SelfHierarchySettings.ParentKeyName = selfHierarchyParentId;
grid.MasterTableView.FilterExpression = selfHierarchyParentId + " = 0";
}
AddColumnsToGridTableView(grid.MasterTableView, columns);
return grid;
}
protected void rgrdMain_PreRender(object sender, EventArgs e)
{
//if (!IsPostBack)
//{
// GridTableView gtv = (sender as RadGrid).MasterTableView;
// if (gtv != null)
// {
// if (gtv.Items.Count > 0)
// gtv.Items[0].Expanded = true;
// }
//}
HideOperationsColumnForChilds((sender as RadGrid).MasterTableView);
}
protected void rgrdMain_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
RadGrid rgrdMain = source as RadGrid;
//if (Convert.ToInt32(ViewState["ID"]) > 0)
//{
// if (Convert.ToString(ViewState["Type"]).Trim() == "Product")
// {
// Product objProd = new Product();
// objProd.ProductId = Convert.ToInt32(ViewState["ID"]);
// rgrdMain.DataSource = objProd.GetProductVariants();
// }
// if (Convert.ToString(ViewState["Type"]).Trim() == "Variant")
// {
// Variant objVar = new Variant();
// objVar.VariantId = Convert.ToInt32(ViewState["ID"]);
// rgrdMain.DataSource = objVar.GetVariantFinishedGoods();
// }
//}
if (Convert.ToInt32(ViewState["ItemID"]) >= 0)
{
Item objItem = new Item();
objItem.ItemId = Id;
rgrdMain.DataSource = objItem.GetItemHistory();
objItem = null;
}
if (rgrdMain.DataSource != null)
ramMain.AjaxSettings.AddAjaxSetting(rgrdMain, rgrdMain, this.Page.FindControl("ralpMain") as RadAjaxLoadingPanel);
}
protected void rgrdMain_ItemDataBound(object sender, GridItemEventArgs e)
{
//For 100% width
e.Item.OwnerTableView.Width = new Unit(100, UnitType.Percentage);
if (e.Item.ItemType == GridItemType.CommandItem)
{
//Image imgAssignNew = e.Item.FindControl("imgAssignNew") as Image;
//LinkButton lnkbtnAssignNew = e.Item.FindControl("lnkbtnAssignNew") as LinkButton;
//Image imgCloneBOM = e.Item.FindControl("imgCloneBOM") as Image;
//LinkButton lnkbtnCloneBOM = e.Item.FindControl("lnkbtnCloneBOM") as LinkButton;
//imgCloneBOM.Visible = false;
//lnkbtnCloneBOM.Visible = false;
//Hide CommandItem for Child Tables
if (e.Item.OwnerTableView.ParentItem != null)
e.Item.Visible = false;
//switch (Convert.ToString(ViewState["Type"]).Trim())
switch (Type)
{
case "Product":
//imgAssignNew.Attributes.Add("OnClick", "return ShowSearch('Assign Product - BOM'," + Convert.ToString(ViewState["ID"]).Trim() + ", 'Product'," + Convert.ToString(0).Trim() + ", 'BOM'," + Convert.ToString(0).Trim() + ");");
//lnkbtnAssignNew.Attributes.Add("OnClick", "return ShowSearch('Assign Product - BOM'," + Convert.ToString(ViewState["ID"]).Trim() + ", 'Product'," + Convert.ToString(0).Trim() + ", 'BOM'," + Convert.ToString(0).Trim() + ");");
break;
case "Variant":
//imgAssignNew.Attributes.Add("OnClick", "return ShowSearch('Assign Variant - BOM'," + Convert.ToString(ViewState["ID"]).Trim() + ", 'Variant'," + Convert.ToString(0).Trim() + ", 'BOM'," + Convert.ToString(0).Trim() + ");");
//lnkbtnAssignNew.Attributes.Add("OnClick", "return ShowSearch('Assign Variant - BOM'," + Convert.ToString(ViewState["ID"]).Trim() + ", 'Variant'," + Convert.ToString(0).Trim() + ", 'BOM'," + Convert.ToString(0).Trim() + ");");
break;
default:
break;
}
}
if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
{
RadToolTip rttHistory = e.Item.FindControl("rttHistory") as RadToolTip;
//ImageButton imgbtnEdit = e.Item.FindControl("imgbtnEdit") as ImageButton;
ImageButton imgbtnHistory = e.Item.FindControl("imgbtnHistory") as ImageButton;
//ImageButton imgbtnDelete = e.Item.FindControl("imgbtnDelete") as ImageButton;
if (e.Item.OwnerTableView.Name == "Variant")
{
Variant objVar = e.Item.DataItem as Variant;
LinkButton lnkbtnVariantNo = e.Item.FindControl("lnkbtnVariantNo") as LinkButton;
//imgbtnEdit.Visible = true;
lnkbtnVariantNo.Text = objVar.VariantNo;
rttHistory.Text = GeneralData.GetHistoryTooltipText(objVar.Deleted, objVar.CreatedOn, objVar.CreatedBy, objVar.LastModifiedOn, objVar.LastModifiedBy);
//imgbtnEdit.Attributes.Add("OnClick", "return EditBOMVariant(" + objVar.VariantId.ToString() + "); return false;");
lnkbtnVariantNo.Attributes.Add("OnClick", "if(window.parent){window.parent.openMasterInNewWindow('var','" + objVar.VariantId.ToString() + "');} return false;");
//imgbtnDelete.Attributes.Add("OnClick", "return confirm('Are you sure to delete this record?');");
}
if (e.Item.OwnerTableView.Name == "FinishedGood")
{
FinishedGood objFg = e.Item.DataItem as FinishedGood;
LinkButton lnkbtnSize = e.Item.FindControl("lnkbtnSize") as LinkButton;
LinkButton lnkbtnRoutingMaster = e.Item.FindControl("lnkbtnRoutingMaster") as LinkButton;
//imgbtnEdit.Visible = false;
lnkbtnSize.Text = objFg.Size;
if (lnkbtnRoutingMaster != null)
{
lnkbtnRoutingMaster.Text = objFg.RoutingMaster.ToString();
lnkbtnRoutingMaster.Visible = true;
if (objFg.RoutingMaster > 0)
lnkbtnRoutingMaster.Attributes.Add("OnClick", "if(window.parent){window.parent.openMasterInNewWindow('rout','" + objFg.RoutingMaster.ToString() + "');} return false;");
else
lnkbtnRoutingMaster.Visible = false;
}
rttHistory.Text = GeneralData.GetHistoryTooltipText(objFg.Deleted, objFg.CreatedOn, objFg.CreatedBy, objFg.LastModifiedOn, objFg.LastModifiedBy);
lnkbtnSize.Attributes.Add("OnClick", "if(window.parent){window.parent.openMasterInNewWindow('fgood','" + objFg.FinishedGoodId.ToString() + "');} return false;");
//imgbtnDelete.Attributes.Add("OnClick", "return confirm('Are you sure to delete this record?');");
}
}
}
protected void rgrdMain_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.ExpandCollapseCommandName)
{
if (!e.Item.Expanded)
{
//Only for Item grid in NeadtedTemplet
if (e.Item.OwnerTableView.Name == "Item")
{
//Rebind Child Item Grid on Expand
RadGrid grid = ((GridDataItem)e.Item).ChildItem.FindControl("rgrdItem") as RadGrid;
grid.Rebind();
}
}
RadAjaxManager.GetCurrent(this.Page).ResponseScripts.Add("if(window.parent){if(window.parent.resizeIFrame){window.parent.resizeIFrame();}}");
}
}
我的代码哪里有问题请帮忙!!!
我猜想在加载用户控件时出现服务器错误。在这里设置一个断点,看看 userControl 是否是你所期望的。 panel.Controls.Add(用户控件); AJAX 的棘手之处在于您可能会遇到服务器错误,并且 UI 中不会有任何指示。