Hi
I use detailedtable in radgrid. Everything goes well as screenshot shows. However, when I try to set dataformat of column in Grid, the detailedtable does not show anymore. It seems expand icon does trigger event DetailTableDataBind and detailedtable.datasource does has data. It confuses me that why the detailedtable disappears.
Can anyone help me? Thank you in advance.
here is my code
I use detailedtable in radgrid. Everything goes well as screenshot shows. However, when I try to set dataformat of column in Grid, the detailedtable does not show anymore. It seems expand icon does trigger event DetailTableDataBind and detailedtable.datasource does has data. It confuses me that why the detailedtable disappears.
Can anyone help me? Thank you in advance.
here is my code
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using Control.UserRequest;using Control.Global;using Control.Position_C;using Control.Salesman_C;using Control.Depart_C;using Model;using Telerik.Web.UI;using Control.Bill_C;namespace ERP.SalesAnalysis{ public partial class BillByCustMonth : Is_Login { private UserRequestController urc = null; IList<Cust> custList = null; IList<Dept> departList = null; IList<Salesman> salesList = null; static string digit = ""; protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { urc = GlobalUserController.get_login_user_request_controller(Session["userID"].ToString()); string permitString = urc.getBillByCustMonthPermit(); LoadPosition(); LoadCustomerComboBox(urc); LoadDepartment(); LoadSalesman(); setPermit(permitString, urc); YearComboBox.SelectedValue = DateTime.Now.Year.ToString(); decimal p = SystemParamController.param.amt_point; //decimal p = 2; for test digit = ""; for (decimal i = 0; i < p; i++) { digit += "0"; } if (digit != "") { digit = "{0:#,#." + digit + "}"; } else { digit = "{0:#,#}"; } } } private void LoadSalesman() { salesList = SalesmanController.getAllSalesmanList(); if (salesList.Count != 0) for (int i = 0; i < salesList.Count; i++) { SalesmanComboBox1.Items.Add(new RadComboBoxItem(salesList[i].salesmanId.deptcode + "\t" + salesList[i].salesmanId.name, salesList[i].salesmanId.name)); SalesmanComboBox2.Items.Add(new RadComboBoxItem(salesList[i].salesmanId.deptcode + "\t" + salesList[i].salesmanId.name, salesList[i].salesmanId.name)); } SalesmanComboBox1.ClearSelection(); SalesmanComboBox2.ClearSelection(); } private void LoadDepartment() { departList = DepartController.getDepartList(); DepartComboBox1.DataSource = departList; DepartComboBox1.DataTextField = "deptcode"; DepartComboBox1.DataValueField = "deptcode"; DepartComboBox1.DataBind(); DepartComboBox2.DataSource = departList; DepartComboBox2.DataTextField = "deptcode"; DepartComboBox2.DataValueField = "deptcode"; DepartComboBox2.DataBind(); } private void setPermit(string permitString, UserRequestController urc) { } protected void LoadPosition() { PositionComboBox.DataSource = PositionController.getPositionList(); PositionComboBox.DataTextField = "p_code"; PositionComboBox.DataValueField = "p_code"; PositionComboBox.DataBind(); } protected void LoadCustomerComboBox(UserRequestController urc) { custList = urc.getCustomerListByUser(); CustomerComboBox1.HighlightTemplatedItems = true; CustomerComboBox1.DataSource = custList; CustomerComboBox1.DataTextField = "c_code"; CustomerComboBox1.DataValueField = "c_code"; CustomerComboBox1.DataBind(); CustomerComboBox2.HighlightTemplatedItems = true; CustomerComboBox2.DataSource = custList; CustomerComboBox2.DataTextField = "c_code"; CustomerComboBox2.DataValueField = "c_code"; CustomerComboBox2.DataBind(); } protected void BillGrid_PreRender(object sender, System.EventArgs e) { setFormat(); } protected void setFormat() { string format = digit; if (!StandardCurrency.Checked) { format = "{0:#,#.00}"; } foreach (GridColumn column in BillGrid.Columns) { if (column.UniqueName == "Sales1" || column.UniqueName == "Sales2" || column.UniqueName == "Sales3" || column.UniqueName == "Sales4" || column.UniqueName == "Sales5" || column.UniqueName == "Sales6" || column.UniqueName == "Sales7" || column.UniqueName == "Sales8" || column.UniqueName == "Sales9" || column.UniqueName == "Sales10" || column.UniqueName == "Sales11" || column.UniqueName == "Sales12") { (column as GridBoundColumn).DataFormatString = format; } else if (column.UniqueName == "Sum" || column.UniqueName == "Avg") { (column as GridCalculatedColumn).DataFormatString = format; } } BillGrid.Rebind(); } protected void BillGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e) { if (!e.IsFromDetailTable) { string year = YearComboBox.SelectedValue; string position = PositionComboBox.SelectedValue; string startDept = DepartComboBox1.SelectedValue; string endDept = DepartComboBox2.SelectedValue; string startSales = SalesmanComboBox1.SelectedValue; string endSales = SalesmanComboBox2.SelectedValue; string startCust = CustomerComboBox1.SelectedValue; string endCust = CustomerComboBox2.SelectedValue; bool standard = true; if (!StandardCurrency.Checked) { standard = false; } BillGrid.DataSource = BillController.getBill(year, position, startDept, endDept, startSales, endSales, startCust, endCust, standard); } } protected void RadGrid1_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e) { GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem; switch (e.DetailTableView.Name) { case "BillDetails": { string year = YearComboBox.SelectedValue; string position = PositionComboBox.SelectedValue; string startCust = CustomerComboBox1.SelectedValue; string endCust = CustomerComboBox2.SelectedValue; bool standard = true; if (!StandardCurrency.Checked) { standard = false; } string salesman = dataItem.GetDataKeyValue("Salesman").ToString(); e.DetailTableView.DataSource = BillController.getBillBySaleman(year, position, salesman, startCust, endCust,standard); //e.DetailTableView.Rebind(); break; } } } protected void SearchButton_Click(object sender, EventArgs e) { string year = YearComboBox.SelectedValue; string position = PositionComboBox.SelectedValue; string startDept = DepartComboBox1.SelectedValue; string endDept = DepartComboBox2.SelectedValue; string startSales = SalesmanComboBox1.SelectedValue; string endSales = SalesmanComboBox2.SelectedValue; string startCust = CustomerComboBox1.SelectedValue; string endCust = CustomerComboBox2.SelectedValue; bool standard = true; if (!StandardCurrency.Checked) { standard = false; } BillGrid.DataSource = BillController.getBill(year, position, startDept, endDept, startSales, endSales, startCust, endCust, standard); BillGrid.Rebind(); setFormat(); } }}<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="BillByCustMonth.aspx.cs" Inherits="ERP.SalesAnalysis.BillByCustMonth" %><%@ Register Assembly="Telerik.ReportViewer.WebForms, Version=6.0.12.302, Culture=neutral, PublicKeyToken=a9d7983dfcc261be" Namespace="Telerik.ReportViewer.WebForms" TagPrefix="telerik" %><%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %><asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server"></asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"><telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="SearchButton"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="BillGrid" /> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings></telerik:RadAjaxManager><table width="100%"><tr><td><asp:label id="PositionLabel" runat="server" Text="<%$ Resources:language,position%>"></asp:label></td><td> <telerik:RadComboBox ID="PositionComboBox" Runat="server" Width="150px" Height="150px"> <headertemplate> <table style="width:100px;"> <tr> <td style="width:40px;">编码</td> <td style="width:60px;">名称</td> </tr> </table> </headertemplate> <itemtemplate> <table style="width:100px;"> <tr> <td style="width:40px;"><%# DataBinder.Eval(Container.DataItem, "p_code") %></td> <td style="width:60px;"><%# DataBinder.Eval(Container.DataItem, "p_name") %></td> </tr> </table> </itemtemplate> </telerik:RadComboBox></td><td><asp:label id="Label1" runat="server" Text="<%$ Resources:language,department%>"></asp:label></td><td><telerik:RadComboBox ID="DepartComboBox1" Runat="server" Width="150px" AllowCustomText="True" Height="150px" > <headertemplate> <table style="width:100px;"> <tr> <td style="width:40px;">编码</td> <td style="width:60px;">名称</td> </tr> </table> </headertemplate> <itemtemplate> <table style="width:100px;"> <tr> <td style="width:40px;"><%# DataBinder.Eval(Container.DataItem, "deptcode")%></td> <td style="width:60px;"><%# DataBinder.Eval(Container.DataItem, "deptname")%></td> </tr> </table> </itemtemplate> </telerik:RadComboBox></td><td><telerik:RadComboBox ID="DepartComboBox2" Runat="server" Width="150px" AllowCustomText="True" Height="150px"> <headertemplate> <table style="width:100px;"> <tr> <td style="width:40px;">编码</td> <td style="width:60px;">名称</td> </tr> </table> </headertemplate> <itemtemplate> <table style="width:100px;"> <tr> <td style="width:40px;"><%# DataBinder.Eval(Container.DataItem, "deptcode")%></td> <td style="width:60px;"><%# DataBinder.Eval(Container.DataItem, "deptname")%></td> </tr> </table> </itemtemplate> </telerik:RadComboBox></td><td><asp:label id="Label2" runat="server" Text="<%$ Resources:language,salesman%>"></asp:label></td><td><telerik:RadComboBox ID="SalesmanComboBox1" Runat="server" Height="150px" Width="100px" AllowCustomText="True" > </telerik:RadComboBox></td><td><telerik:RadComboBox ID="SalesmanComboBox2" Runat="server" Height="150px" Width="100px" AllowCustomText="True" > </telerik:RadComboBox></td></tr><tr><td><asp:label id="Label3" runat="server" Text="<%$ Resources:language,year%>"></asp:label></td><td><telerik:RadComboBox ID="YearComboBox" Runat="server" Filter="StartsWith" Width="100px" Height="150px" DataTextField="Text" DataValueField="Value" DataSourceID="XmlDataSource1" ></telerik:RadComboBox> <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/Common/year.xml"></asp:XmlDataSource></td><td><asp:label id="Label4" runat="server" Text="<%$ Resources:language,customerID%>"></asp:label></td><td><telerik:RadComboBox ID="CustomerComboBox1" Runat="server" AllowCustomText="True" Height="250px" > <headertemplate> <table style="width:160px"> <tr> <td style="width:60px;">编码</td> <td style="width:100px;">名称</td> </tr> </table> </headertemplate> <itemtemplate> <table style="width:160px"> <tr> <td style="width:60px;"><%# DataBinder.Eval(Container.DataItem, "c_code") %></td> <td style="width:100px;"><%# DataBinder.Eval(Container.DataItem, "c_abrname") %></td> </tr> </table> </itemtemplate> </telerik:RadComboBox></td> <td><telerik:RadComboBox ID="CustomerComboBox2" Runat="server" Height="250px" AllowCustomText="True" > <headertemplate> <table style="width:160px"> <tr> <td style="width:60px;">编码</td> <td style="width:100px;">名称</td> </tr> </table> </headertemplate> <itemtemplate> <table style="width:160px"> <tr> <td style="width:60px;"><%# DataBinder.Eval(Container.DataItem, "c_code") %></td> <td style="width:100px;"><%# DataBinder.Eval(Container.DataItem, "c_abrname")%></td> </tr> </table> </itemtemplate> </telerik:RadComboBox></td><td><asp:label id="Label5" runat="server" Text="<%$ Resources:language,currency%>"></asp:label></td><td><asp:RadioButton ID="StandardCurrency" runat="server" Text="<%$ Resources:language,standardCurrency%>" Checked="true" GroupName="currency"></asp:RadioButton><asp:RadioButton ID="ForeCurrency" runat="server" Text="<%$ Resources:language,foreCurrency%>" GroupName="currency"></asp:RadioButton></td></tr><tr><td colspan="8" align="right"><telerik:RadButton runat="server" ID="SearchButton" Text="<%$ Resources:language,search%>" onclick="SearchButton_Click"></telerik:RadButton></td></tr></table> <telerik:RadGrid ID="BillGrid" Width="100%" runat="server" Height="375px" AllowPaging="true" AutoGenerateColumns="False" PageSize="10" AllowSorting="True" OnNeedDataSource="BillGrid_NeedDataSource" OnPreRender="BillGrid_PreRender" OnDetailTableDataBind="RadGrid1_DetailTableDataBind" Skin="Office2010Blue" > <MasterTableView Width="100%" AllowMultiColumnSorting="false" GroupLoadMode="Server" DataKeyNames="Salesman" ShowFooter="true" CssClass="number"> <DetailTables> <telerik:GridTableView DataKeyNames="Salesman" Name="BillDetails" Width="100%" ShowFooter="false" ShowHeader="false" CssClass="number" > <Columns> <telerik:GridBoundColumn HeaderStyle-Width="80px" DataField="Blanck"></telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderStyle-Width="80px" DataField="Blanck"></telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderStyle-Width="90px" DataField="Custcode"></telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderStyle-Width="90px" DataField="Custname"></telerik:GridBoundColumn> <telerik:GridBoundColumn UniqueName="Sales21" HeaderStyle-Width="80px" DataField="Sales1" DataFormatString="{0:###,###.##}"></telerik:GridBoundColumn> <telerik:GridBoundColumn UniqueName="Sales22" HeaderStyle-Width="80px" DataField="Sales2" DataFormatString="{0:###,###.##}"></telerik:GridBoundColumn> <telerik:GridBoundColumn UniqueName="Sales23" HeaderStyle-Width="80px" DataField="Sales3" DataFormatString="{0:###,###.##}"></telerik:GridBoundColumn> <telerik:GridBoundColumn UniqueName="Sales24" HeaderStyle-Width="80px" DataField="Sales4" DataFormatString="{0:###,###.##}"></telerik:GridBoundColumn> <telerik:GridBoundColumn UniqueName="Sales25" HeaderStyle-Width="80px" DataField="Sales5" DataFormatString="{0:###,###.##}"></telerik:GridBoundColumn> <telerik:GridBoundColumn UniqueName="Sales26" HeaderStyle-Width="80px" DataField="Sales6" DataFormatString="{0:###,###.##}"></telerik:GridBoundColumn> <telerik:GridBoundColumn UniqueName="Sales27" HeaderStyle-Width="80px" DataField="Sales7" DataFormatString="{0:###,###.##}"></telerik:GridBoundColumn> <telerik:GridBoundColumn UniqueName="Sales28" HeaderStyle-Width="80px" DataField="Sales8" DataFormatString="{0:###,###.##}"></telerik:GridBoundColumn> <telerik:GridBoundColumn UniqueName="Sales29" HeaderStyle-Width="80px" DataField="Sales9" DataFormatString="{0:###,###.##}"></telerik:GridBoundColumn> <telerik:GridBoundColumn UniqueName="Sales210" HeaderStyle-Width="80px" DataField="Sales10" DataFormatString="{0:###,###.##}"></telerik:GridBoundColumn> <telerik:GridBoundColumn UniqueName="Sales211" HeaderStyle-Width="80px" DataField="Sales11" DataFormatString="{0:###,###.##}"></telerik:GridBoundColumn> <telerik:GridBoundColumn UniqueName="Sales212" HeaderStyle-Width="80px" DataField="Sales12" DataFormatString="{0:###,###.##}"></telerik:GridBoundColumn> <telerik:GridCalculatedColumn UniqueName="Sum2" HeaderStyle-Width="80px" DataFields="Sales1,Sales2,Sales3,Sales4,Sales5,Sales6,Sales7,Sales8,Sales9,Sales10,Sales11,Sales12" Expression="{0}+{1}+{2}+{3}+{4}+{5}+{6}+{7}+{8}+{9}+{10}+{11}" DataFormatString="{0:###,###.##}"></telerik:GridCalculatedColumn> <telerik:GridCalculatedColumn UniqueName="Avg2" HeaderStyle-Width="80px" DataFields="Sales1,Sales2,Sales3,Sales4,Sales5,Sales6,Sales7,Sales8,Sales9,Sales10,Sales11,Sales12" Expression="({0}+{1}+{2}+{3}+{4}+{5}+{6}+{7}+{8}+{9}+{10}+{11})/12" DataFormatString="{0:###,###.##}"></telerik:GridCalculatedColumn> </Columns> </telerik:GridTableView> </DetailTables> <Columns> <telerik:GridBoundColumn HeaderText="<%$ Resources:language,department%>" HeaderStyle-Width="80px" DataField="Depart"></telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderText="<%$ Resources:language,salesman%>" HeaderStyle-Width="80px" DataField="Salesman"></telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderText="<%$ Resources:language,customerId%>" HeaderStyle-Width="90px" DataField="Custcode"></telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderText="<%$ Resources:language,customerName%>" HeaderStyle-Width="90px" DataField="Custname"></telerik:GridBoundColumn> <telerik:GridNumericColumn HeaderText="1月份" UniqueName="Sales1" HeaderStyle-Width="80px" DataField="Sales1" Aggregate="Sum"></telerik:GridNumericColumn> <telerik:GridNumericColumn HeaderText="2月份" UniqueName="Sales2" HeaderStyle-Width="80px" DataField="Sales2" Aggregate="Sum"></telerik:GridNumericColumn> <telerik:GridNumericColumn HeaderText="3月份" UniqueName="Sales3" HeaderStyle-Width="80px" DataField="Sales3" Aggregate="Sum"></telerik:GridNumericColumn> <telerik:GridNumericColumn HeaderText="4月份" UniqueName="Sales4" HeaderStyle-Width="80px" DataField="Sales4" Aggregate="Sum"></telerik:GridNumericColumn> <telerik:GridNumericColumn HeaderText="5月份" UniqueName="Sales5" HeaderStyle-Width="80px" DataField="Sales5" Aggregate="Sum"></telerik:GridNumericColumn> <telerik:GridNumericColumn HeaderText="6月份" UniqueName="Sales6" HeaderStyle-Width="80px" DataField="Sales6" Aggregate="Sum"></telerik:GridNumericColumn> <telerik:GridNumericColumn HeaderText="7月份" UniqueName="Sales7" HeaderStyle-Width="80px" DataField="Sales7" Aggregate="Sum"></telerik:GridNumericColumn> <telerik:GridNumericColumn HeaderText="8月份" UniqueName="Sales8" HeaderStyle-Width="80px" DataField="Sales8" Aggregate="Sum"></telerik:GridNumericColumn> <telerik:GridNumericColumn HeaderText="9月份" UniqueName="Sales9" HeaderStyle-Width="80px" DataField="Sales9" Aggregate="Sum"></telerik:GridNumericColumn> <telerik:GridNumericColumn HeaderText="10月份" UniqueName="Sales10" HeaderStyle-Width="80px" DataField="Sales10" Aggregate="Sum"></telerik:GridNumericColumn> <telerik:GridNumericColumn HeaderText="11月份" UniqueName="Sales11" HeaderStyle-Width="80px" DataField="Sales11" Aggregate="Sum"></telerik:GridNumericColumn> <telerik:GridNumericColumn HeaderText="12月份" UniqueName="Sales12" HeaderStyle-Width="80px" DataField="Sales12" Aggregate="Sum"></telerik:GridNumericColumn> <telerik:GridCalculatedColumn HeaderText="总计" UniqueName="Sum" HeaderStyle-Width="80px" DataFields="Sales1,Sales2,Sales3,Sales4,Sales5,Sales6,Sales7,Sales8,Sales9,Sales10,Sales11,Sales12" Expression="{0}+{1}+{2}+{3}+{4}+{5}+{6}+{7}+{8}+{9}+{10}+{11}" ></telerik:GridCalculatedColumn> <telerik:GridCalculatedColumn HeaderText="月平均" UniqueName="Avg" HeaderStyle-Width="80px" DataFields="Sales1,Sales2,Sales3,Sales4,Sales5,Sales6,Sales7,Sales8,Sales9,Sales10,Sales11,Sales12" Expression="({0}+{1}+{2}+{3}+{4}+{5}+{6}+{7}+{8}+{9}+{10}+{11})/12"></telerik:GridCalculatedColumn> </Columns> </MasterTableView> <ClientSettings> <Selecting AllowRowSelect="True"></Selecting> <Resizing AllowColumnResize="true" EnableRealTimeResize="True"/> <Scrolling UseStaticHeaders="true" AllowScroll="true" /> </ClientSettings> </telerik:RadGrid></asp:Content>