I have a grid with autogeneratedcolumns = true and I have a details
table inside of that grid with autogeneratedcolumns = true, have a
dropdown box where user selects a particular month, every time the
month changes the field names and values of the parent and detail grid
change. So if for example selected month is Feb, 2013, set of generated
fields would be "sales_12_2012", "sales_1_2013", sales_2_2013" and when I
expend detail table it would have similar fields with an addition of
some detail information like employee name for example ("empname",
"sales_details_1_2013", "sales_details_2_2013", sales_details_3_2013"),
and when the selected month would change to Mar, 2013 the set of
generated fields would become "sales_1_2013",
"sales_2_2013", sales_3_2013"...
As user gets to the page originally everything works fine, user expends the detail table and proper columns are shown (by default current month is selected so it's March, 2013 and therefore it shows: "empname", "sales_details_1_2013", "sales_details_2_2013", sales_details_3_2013") but if user then changes the month to Feb, 2013 for example, so query changes and has the following fields now: "empname", "sales_details_12_2012", "sales_details_1_2013", sales_details_2_2013", but when user expends the detail table again, the set of columns is still the same ("empname", "sales_details_1_2013", "sales_details_1_2013", sales_details_3_2013") as the original one in the details grid. Main "parent" grid works fine.
Please help, it's urgent. Thanks.
ASPX code:
VB Code:
As user gets to the page originally everything works fine, user expends the detail table and proper columns are shown (by default current month is selected so it's March, 2013 and therefore it shows: "empname", "sales_details_1_2013", "sales_details_2_2013", sales_details_3_2013") but if user then changes the month to Feb, 2013 for example, so query changes and has the following fields now: "empname", "sales_details_12_2012", "sales_details_1_2013", sales_details_2_2013", but when user expends the detail table again, the set of columns is still the same ("empname", "sales_details_1_2013", "sales_details_1_2013", sales_details_3_2013") as the original one in the details grid. Main "parent" grid works fine.
Please help, it's urgent. Thanks.
ASPX code:
<telerik:RadComboBox ID="rcbMonth" AutoPostBack="True" CausesValidation="False" Rows="1" runat="server"> </telerik:RadComboBox><telerik:RadGrid ShowGroupPanel="false" AutoGenerateColumns="True" ID="RadGrid1" AllowFilteringByColumn="False" AllowSorting="false" ShowFooter="True" runat="server" GridLines="None" AllowPaging="false" EnableLinqExpressions="false" FooterStyle-BackColor="LightGray" > <ExportSettings HideStructureColumns="False" ExportOnlyData="true" IgnorePaging="true" OpenInNewWindow="true"> <Excel Format="Html" /> </ExportSettings> <MasterTableView Name="ParentGrid" DataKeyNames="Name" ShowGroupFooter="true" AllowMultiColumnSorting="true" CommandItemDisplay="Top" CommandItemSettings-ShowAddNewRecordButton="False" CommandItemSettings-ShowRefreshButton="False" ShowFooter="True"> <CommandItemSettings ShowExportToWordButton="False" ShowExportToExcelButton="true" ShowExportToCsvButton="False" /> <DetailTables> <telerik:GridTableView DataKeyNames="NameDetail" runat="server" AutoGenerateColumns="True" Name="Details" ShowFooter="False" AllowPaging="False" HorizontalAlign="center" GridLines="None"> <Columns> </Columns> </telerik:GridTableView> </DetailTables> <Columns> </Columns> </MasterTableView> </telerik:RadGrid>VB Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) If Not Page.IsPostBack Then Dim reportdefaultdate As Date = DateAdd("m", -1, DateTime.Now.Date) Dim reportdefaultmonth As Date = CDate(CStr(Month(reportdefaultdate)) & "/1/" & CStr(Year(reportdefaultdate))) Dim loopdate As Date = reportdefaultmonth.Date Do While loopdate >= CDate("7/1/2012") Dim item As New RadComboBoxItem() item.Text = MonthName(Month(loopdate)) & ", " & Year(loopdate) item.Value = loopdate rcbMonth.Items.Add(item) loopdate = DateAdd("m", -1, loopdate) Loop End If End Sub Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource Dim var_monthval As Date = rcbMonth.SelectedValue sql= " select " Dim loopdate As Date = DateAdd("m", -2, var_monthval) Dim var_columnname As String = "" Dim i As Integer = 0 Do While loopdate <= CDate(var_monthval) i += 1 var_columnname = "sales_" & Month(loopdate) & "_" & Year(loopdate) If i > 1 Then sql += "," sql += " sales as " & var_columnname loopdate = DateAdd("m", 1, loopdate) Loop sql += " from table where month between '" & DateAdd("m", -2, var_monthval) & "' and '" & var_monthval & "' " RadGrid1.DataSource = GetDataTable(Sql) End SubPrivate Sub RadGrid1_DetailTableDataBind(ByVal source As Object, ByVal e As GridDetailTableDataBindEventArgs) Handles RadGrid1.DetailTableDataBind Dim var_monthval As Date = rcbMonth.SelectedValue Dim dataItem As GridDataItem = CType(e.DetailTableView.ParentItem, GridDataItem) Dim var_datakeyval As String = dataItem.GetDataKeyValue("Name").ToString() sql= " select name " Dim loopdate As Date = DateAdd("m", -2, var_monthval) Dim var_columnname As String = "" Do While loopdate <= CDate(var_monthval) var_columnname = "sales_" & Month(loopdate) & "_" & Year(loopdate) sql += " , sales as " & var_columnname loopdate = DateAdd("m", 1, loopdate) Loop sql += " from table where month between '" & DateAdd("m", -2, var_monthval) & "' and '" & var_monthval & "' and name = '" & var_datakeyval & "' " e.DetailTableView.DataSource = GetDataTable(Sql)End SubProtected Sub rcbMonth_IndexChanged(ByVal sender As Object, ByVal e As RadComboBoxSelectedIndexChangedEventArgs) Handles rcbMonth.SelectedIndexChanged RadGrid1.MasterTableView.Rebind() End SubPublic Function GetDataTable(ByVal query As String) As DataTable Dim conn As SqlConnection = New SqlConnection(ConnString) Dim adapter As SqlDataAdapter = New SqlDataAdapter adapter.SelectCommand = New SqlCommand(query, conn) Dim table1 As New DataTable conn.Open() Try adapter.Fill(table1) Finally conn.Close() End Try Return table1 End Function