This is a migrated thread and some comments may be shown as answers.

Dynamic Radgrid adding Extra Column at Each postback

6 Answers 322 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Balkar
Top achievements
Rank 1
Balkar asked on 23 May 2013, 06:04 PM
I have a dynamic grid which is created in page_init. The column of the grid are dynamic. Each times when i pick the new dates some blank column are added to dynamic grid. Please see attached fille.



Aspx file:
<%@ Page Language="C#" MaintainScrollPositionOnPostback="true" AutoEventWireup="true"
    EnableEventValidation="false" CodeFile="HinoPartsDashboard.aspx.cs" Inherits="Dashboard_HinoPartsDashboard" %>
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register TagPrefix="HinoDataControl" TagName="HinoDataSelect" Src="~/Components/HinoDataSelect.ascx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title>Hino Dashboard</title>
    <link rel="stylesheet" type="text/css" href="../Includes/StyleSheets/Dashboard.css" />
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Height="75px"
        Width="75px">
        <asp:Image ID="Image1" runat="server" AlternateText="Loading..." ImageUrl="../Images/circle.gif" />
    </telerik:RadAjaxLoadingPanel>
    <div class="pageheader">
        <h1>
            Dashboard</h1>
        <p>
            <asp:Label ID="lblLastRefreshDate" Font-Size="11px" runat="Server" Text="Last Refresh Date:"></asp:Label>
            <br />
            <a href="HinoDashboard_Main.aspx" id="backButton" runat="server">Dashboard Home</a>
        </p>
        <a></a>
    </div>
    <div class="filters">
        <fieldset>
            <legend>Filters</legend>
            <dl>
                <dt>From Month/Year</dt>
                <dl>
                    <dt>From Month</dt>
                    <dd>
                        <asp:DropDownList ID="FromMonthDropDownList" runat="server" AutoPostBack="True" OnSelectedIndexChanged="MonthDropDownList_SelectedIndexChanged" />
                    </dd>
                    <dt>To Month</dt>
                    <dd>
                        <asp:DropDownList ID="ToMonthDropDownList" runat="server" AutoPostBack="True" OnSelectedIndexChanged="MonthDropDownList_SelectedIndexChanged" />
                    </dd>
                    <dd class="break">
                    </dd>
                    <dd style="margin-left: 0px">
                        <asp:CheckBox ID="chkDealer" runat="server" Text="Display By Dealers" AutoPostBack="true"
                            Checked="true" /></dd>
                    <dd style="margin-left: 0px">
                        <asp:CheckBox ID="chkVendor" runat="server" Text="Display By Vendors" AutoPostBack="true" /></dd>
                </dl>
        </fieldset>
        <fieldset>
            <legend>Export Options</legend>
            <dl>
                <dd style="margin-left: 0px">
                    <asp:CheckBox ID="chk1" Text="Export only data" runat="server"></asp:CheckBox></dd>
                <dd style="margin-left: 0px">
                    <asp:CheckBox ID="chk4" Text="Expand Grid" runat="server" /></dd>
                <dd style="margin-left: 0px">
                    <asp:CheckBox ID="chk2" Text="Export all Pages" runat="server"></asp:CheckBox></dd>
                <dd style="margin-left: 0px">
                    <asp:CheckBox ID="chk3" Text="Open in new window" runat="server"></asp:CheckBox></dd>
                <dd style="margin-left: 0px">
                    <asp:Button ID="btnExport" Text="Export" OnClick="btnExport_Click" runat="server">
                    </asp:Button></dd>
            </dl>
        </fieldset>
    </div>
    <div class="data" style="width: 60%; top: 0px; left: 0px;">
        <input type="hidden" runat="server" name="dist" value="" id="dist" />
        <asp:Panel ID="pnlSalesParts" runat="server" Width="100%" Visible="true">
            <telerik:RadGrid runat="server" ID="rgPartDashboard" ShowFooter="true" AllowFilteringByColumn="false"
                AutoGenerateColumns="false" HorizontalAlign="Left" AllowSorting="false" EnableLinqExpressions="false"
                PageSize="10" Width="100%" ShowGroupPanel="false" OnNeedDataSource="rgPartDashboard_Load"
                OnDetailTableDataBind="rgPartDashboard_Detail" ShowStatusBar="true" Skin="Outlook"
                AllowPaging="false" GridLines="Both" OnPreRender="rgPartDashboard_PreRender">
                <ClientSettings EnableRowHoverStyle="true">
                </ClientSettings>
                <MasterTableView DataKeyNames="user_id" AllowMultiColumnSorting="True" HorizontalAlign="Right"
                    Width="100%" ShowFooter="true" CssClass="MasterClass" Caption="Sales 02 Parts">
                    <DetailTables>
                        <telerik:GridTableView Name="Dealers" AutoGenerateColumns="false" DataKeyNames="dealer_id"
                            AllowFilteringByColumn="false" AllowSorting="false" AllowPaging="false" Width="100%"
                            ShowFooter="true" ShowHeader="false" DataSourceID="SqlDataSource2" HorizontalAlign="Right"
                            CssClass="DetailClass">
                            <Columns>
                                <telerik:GridBoundColumn SortExpression="DealerName" HeaderText="DealerName" DataField="Dealer_Name"
                                    UniqueName="Dealer_Name" ItemStyle-Width="225px">
                                </telerik:GridBoundColumn>
                                <telerik:GridTemplateColumn Aggregate="Sum" DataField="HO_sales" UniqueName="HO_sales"
                                    ItemStyle-Width="70px" HeaderStyle-Font-Bold="true" FooterAggregateFormatString="{0:F2}"
                                    FooterStyle-Font-Bold="true">
                                    <HeaderTemplate>
                                        HO Sales
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <a href="HinoPartsDashBoardTransactions.aspx?TransType=S&type=Dealer&SalesType=HO&_name=<%#GetDPMPlusDealer(Eval("DPM_Name").ToString(),Eval("Dealer_Name").ToString())%>&DPM=<%#Eval("User_ID")%>&from=<%#FromMonthDropDownList.SelectedValue%>&to=<%#ToMonthDropDownList.SelectedValue%>&DealerID=<%#Eval("Dealer_ID")%>">
                                            <%#Eval("HO_sales")%></a>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn Aggregate="Sum" DataField="HO_Goal" UniqueName="HO_Goal"
                                    ItemStyle-Width="70px" HeaderStyle-Font-Bold="true" FooterAggregateFormatString="{0:F2}"
                                    FooterStyle-Font-Bold="true">
                                    <HeaderTemplate>
                                        HO_Goal
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <a href="HinoPartsDashBoardTransactions.aspx?TransType=G&type=Dealer&SalesType=HO&_name=<%#GetDPMPlusDealer(Eval("DPM_Name").ToString(),Eval("Dealer_Name").ToString())%>&DPM=<%#Eval("User_ID")%>&from=<%#FromMonthDropDownList.SelectedValue%>&to=<%#ToMonthDropDownList.SelectedValue%>&DealerId=<%#Eval("Dealer_ID")%>">
                                            <%#Eval("HO_Goal")%></a>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridCalculatedColumn HeaderText="HO sales Effectiveness" UniqueName="HOSalesEffectiveness"
                                    DataType="System.Double" DataFields="HO_Sales, HO_Goal" Expression="iif({0}=null or {0}=0.00 or {1}=null or {1}=0.00,0.00,({0}/{1})*100)"
                                    ItemStyle-Width="95px" DataFormatString="{0:F2}%" />
                                <telerik:GridTemplateColumn Aggregate="Sum" DataField="AM_Sales" UniqueName="AM_Sales"
                                    ItemStyle-Width="70px" HeaderStyle-Font-Bold="true" FooterAggregateFormatString="{0:F2}"
                                    FooterStyle-Font-Bold="true">
                                    <HeaderTemplate>
                                        AM sales
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <a href="HinoPartsDashBoardTransactions.aspx?TransType=S&type=Dealer&SalesType=AM&_name=<%#GetDPMPlusDealer(Eval("DPM_Name").ToString(),Eval("Dealer_Name").ToString())%>&DPM=<%#Eval("User_ID")%>&from=<%#FromMonthDropDownList.SelectedValue%>&to=<%#ToMonthDropDownList.SelectedValue%>&DealerId=<%#Eval("Dealer_ID")%>">
                                            <%#Eval("AM_Sales")%></a>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn Aggregate="Sum" DataField="AM_GOAL" UniqueName="AM_GOAL"
                                    ItemStyle-Width="65px" HeaderStyle-Font-Bold="true" FooterAggregateFormatString="{0:F2}"
                                    FooterStyle-Font-Bold="true">
                                    <HeaderTemplate>
                                        AM Goal
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <a href="HinoPartsDashBoardTransactions.aspx?TransType=G&type=Dealer&SalesType=AM&_name=<%#GetDPMPlusDealer(Eval("DPM_Name").ToString(),Eval("Dealer_Name").ToString())%>&DPM=<%#Eval("User_ID")%>&from=<%#FromMonthDropDownList.SelectedValue%>&to=<%#ToMonthDropDownList.SelectedValue%>&DealerId=<%#Eval("Dealer_ID")%>">
                                            <%#Eval("AM_GOAL")%></a>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridCalculatedColumn HeaderText="AM Sales Effectiveness" UniqueName="AMEffectiveness"
                                    DataType="System.Double" DataFields="AM_Sales, AM_Goal" Expression="iif({0}=null or {0}=0.00 or {1}=null or {1}=0.00,0.00,({0}/{1})*100)"
                                    ItemStyle-Width="90px" DataFormatString="{0:F2}%" />
                                <telerik:GridTemplateColumn Aggregate="Sum" DataField="Total_Sales" UniqueName="Total_Sales"
                                    ItemStyle-Width="70px" HeaderStyle-Font-Bold="true" FooterAggregateFormatString="{0:F2}"
                                    FooterStyle-Font-Bold="true">
                                    <HeaderTemplate>
                                        Total Sales
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <a href="HinoPartsDashBoardTransactions.aspx?TransType=S&type=Dealer&SalesType=T&_name=<%#GetDPMPlusDealer(Eval("DPM_Name").ToString(),Eval("Dealer_Name").ToString())%>&DPM=<%#Eval("User_ID")%>&from=<%#FromMonthDropDownList.SelectedValue%>&to=<%#ToMonthDropDownList.SelectedValue%>&DealerId=<%#Eval("Dealer_ID")%>">
                                            <%#Eval("Total_Sales")%></a>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn Aggregate="Sum" DataField="Total_Goal" UniqueName="Total_Goal"
                                    ItemStyle-Width="70px" HeaderStyle-Font-Bold="true" FooterAggregateFormatString="{0:F2}"
                                    FooterStyle-Font-Bold="true">
                                    <HeaderTemplate>
                                        Total Goal
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <a href="HinoPartsDashBoardTransactions.aspx?TransType=G&type=Dealer&SalesType=T&_name=<%#GetDPMPlusDealer(Eval("DPM_Name").ToString(),Eval("Dealer_Name").ToString())%>&DPM=<%#Eval("User_ID")%>&from=<%#FromMonthDropDownList.SelectedValue%>&to=<%#ToMonthDropDownList.SelectedValue%>&DealerId=<%#Eval("Dealer_ID")%>">
                                            <%#Eval("Total_Goal")%></a>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridCalculatedColumn HeaderText="Total Sales Effectiveness" UniqueName="TotalEffectiveness"
                                    DataType="System.Double" DataFields="Total_Sales,Total_goal" Expression="iif({0}=null or {0}=0.00 or {1}=null or {1}=0.00,0.00,({0}/{1})*100)"
                                    ItemStyle-Width="90px" DataFormatString="{0:F2}%</a>" />
                            </Columns>
                        </telerik:GridTableView>
                    </DetailTables>
                    <Columns>
                        <telerik:GridBoundColumn SortExpression="DPM_Name" HeaderText="DPM" DataField="DPM_Name"
                            HeaderStyle-Font-Bold="true" UniqueName="DPM_Name" ItemStyle-Width="280px" FooterText="Grand Total:"
                            FooterStyle-Font-Bold="true" ItemStyle-Font-Bold="true" ItemStyle-Font-Size="Medium"
                            ItemStyle-ForeColor="Blue" ItemStyle-BackColor="Beige">
                        </telerik:GridBoundColumn>
                        <telerik:GridTemplateColumn Aggregate="Sum" DataField="HO_sales" UniqueName="HO_sales"
                            ItemStyle-Width="75px" HeaderStyle-Font-Bold="true" FooterAggregateFormatString="{0:F2}"
                            FooterStyle-Font-Bold="true">
                            <HeaderTemplate>
                                HO Sales
                            </HeaderTemplate>
                            <ItemTemplate>
                                <a href="HinoPartsDashBoardTransactions.aspx?TransType=S&type=DPM&SalesType=HO&_name=<%#Eval("DPM_Name")%>&from=<%#FromMonthDropDownList.SelectedValue%>&to=<%#ToMonthDropDownList.SelectedValue%>&DPM=<%#Eval("User_ID")%>">
                                    <%#Eval("HO_sales")%></a>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn Aggregate="Sum" DataField="HO_Goal" UniqueName="HO_Goal"
                            ItemStyle-Width="75px" HeaderStyle-Font-Bold="true" FooterAggregateFormatString="{0:F2}"
                            FooterStyle-Font-Bold="true">
                            <HeaderTemplate>
                                HO Goal
                            </HeaderTemplate>
                            <ItemTemplate>
                                <a href="HinoPartsDashBoardTransactions.aspx?TransType=G&type=DPM&SalesType=HO&_name=<%#Eval("DPM_Name")%>&from=<%#FromMonthDropDownList.SelectedValue%>&to=<%#ToMonthDropDownList.SelectedValue%>&DPM=<%#Eval("User_ID")%>">
                                    <%#Eval("HO_Goal")%></a>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridCalculatedColumn Aggregate="Avg" ItemStyle-Width="100px" HeaderText="HO Sales Effectiveness"
                            UniqueName="HoSalesEffectiveness" HeaderStyle-Font-Bold="true" FooterAggregateFormatString="{0:F2}%"
                            FooterStyle-Font-Bold="true" DataType="System.Double" DataFields="HO_Sales, HO_Goal"
                            Expression="iif({0}=null or {0}=0.00 or {1}=null or {1}=0.00,0.00,({0}/{1})*100)"
                            DataFormatString="{0:F2}%">
                        </telerik:GridCalculatedColumn>
                        <telerik:GridTemplateColumn Aggregate="Sum" DataField="AM_sales" UniqueName="AM_sales"
                            ItemStyle-Width="75px" HeaderStyle-Font-Bold="true" FooterAggregateFormatString="{0:F2}"
                            FooterStyle-Font-Bold="true">
                            <HeaderTemplate>
                                AM Sales
                            </HeaderTemplate>
                            <ItemTemplate>
                                <a href="HinoPartsDashBoardTransactions.aspx?TransType=S&type=DPM&SalesType=AM&_name=<%#Eval("DPM_Name")%>&from=<%#FromMonthDropDownList.SelectedValue%>&to=<%#ToMonthDropDownList.SelectedValue%>&DPM=<%#Eval("User_ID")%>">
                                    <%#Eval("AM_sales")%></a>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn Aggregate="Sum" DataField="AM_GOAL" UniqueName="AM_GOAL"
                            ItemStyle-Width="75px" HeaderStyle-Font-Bold="true" FooterAggregateFormatString="{0:F2}"
                            FooterStyle-Font-Bold="true">
                            <HeaderTemplate>
                                AM Goal
                            </HeaderTemplate>
                            <ItemTemplate>
                                <a href="HinoPartsDashBoardTransactions.aspx?TransType=G&type=DPM&SalesType=AM&_name=<%#Eval("DPM_Name")%>&from=<%#FromMonthDropDownList.SelectedValue%>&to=<%#ToMonthDropDownList.SelectedValue%>&DPM=<%#Eval("User_ID")%>">
                                    <%#Eval("AM_GOAL")%></a>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridCalculatedColumn ItemStyle-Width="100px" HeaderText="AM Sales Effectiveness"
                            UniqueName="AMEffectiveness" HeaderStyle-Font-Bold="true" DataType="System.Double"
                            DataFields="AM_Sales, AM_Goal" Expression="iif({0}=null or {0}=0.00 or {1}=null or {1}=0.00,0.00,({0}/{1})*100)"
                            DataFormatString="{0:F2}%" FooterAggregateFormatString="{0:F2}%" Aggregate="Avg"
                            FooterStyle-Font-Bold="true" />
                        <telerik:GridTemplateColumn Aggregate="Sum" DataField="Total_sales" UniqueName="Total_sales"
                            ItemStyle-Width="75px" HeaderStyle-Font-Bold="true" FooterAggregateFormatString="{0:F2}"
                            FooterStyle-Font-Bold="true">
                            <HeaderTemplate>
                                Total sales
                            </HeaderTemplate>
                            <ItemTemplate>
                                <a href="HinoPartsDashBoardTransactions.aspx?TransType=S&type=DPM&SalesType=T&_name=<%#Eval("DPM_Name")%>&from=<%#FromMonthDropDownList.SelectedValue%>&to=<%#ToMonthDropDownList.SelectedValue%>&DPM=<%#Eval("User_ID")%>">
                                    <%#Eval("Total_sales")%></a>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn Aggregate="Sum" DataType="System.Decimal" DataField="Total_Goal"
                            UniqueName="TotalGoals" ItemStyle-Width="75px" HeaderStyle-Font-Bold="true" FooterAggregateFormatString="{0:F2}"
                            FooterStyle-Font-Bold="true">
                            <HeaderTemplate>
                                Total Goal
                            </HeaderTemplate>
                            <ItemTemplate>
                                <a href="HinoPartsDashBoardTransactions.aspx?TransType=G&type=DPM&SalesType=T&_name=<%#Eval("DPM_Name")%>&from=<%#FromMonthDropDownList.SelectedValue%>&to=<%#ToMonthDropDownList.SelectedValue%>&DMP=<%#Eval("User_ID")%>">
                                    <%#Eval("Total_Goal")%></a>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridCalculatedColumn ItemStyle-Width="100px" HeaderText="Total Sales Effectiveness"
                            HeaderStyle-Font-Bold="true" UniqueName="TotalEffectivenessabc" DataType="System.Double"
                            DataFields="Total_sales,Total_Goal" Expression="iif({0}=null or {0}=0.00 or {1}=0.00,0.00,({0}/{1})*100)"
                            DataFormatString="{0:F2}%" FooterAggregateFormatString="{0:F2}%" Aggregate="Avg"
                            FooterStyle-Font-Bold="true" />
                    </Columns>
                </MasterTableView>
            </telerik:RadGrid>
        </asp:Panel>
        <asp:SqlDataSource ID="SqlDataSource3" ConnectionString="<%$ ConnectionStrings:HinoConnectionString %>"
            ProviderName="System.Data.SqlClient" SelectCommandType="StoredProcedure" SelectCommand="spSelectPartsDashboardSalesByDPM_ForDateRange"
            runat="server">
            <SelectParameters>
                <asp:SessionParameter Name="StartMonth" SessionField="StartMonth" Type="Int32" DefaultValue="01" />
                <asp:SessionParameter Name="StartYear" SessionField="StartYear" Type="Int32" DefaultValue="2012" />
                <asp:SessionParameter Name="EndMonth" SessionField="EndMonth" Type="Int32" DefaultValue="01" />
                <asp:SessionParameter Name="EndYear" SessionField="EndYear" Type="Int32" DefaultValue="2013" />
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource2" ConnectionString="<%$ ConnectionStrings:HinoConnectionString %>"
            ProviderName="System.Data.SqlClient" SelectCommandType="StoredProcedure" SelectCommand="spSelectPartsDashboardSalesByOneDPM_ForDateRange"
            runat="server">
            <SelectParameters>
                <asp:SessionParameter Name="Userid" SessionField="Userid" Type="Int32" DefaultValue="2568" />
                <asp:SessionParameter Name="StartMonth" SessionField="StartMonth" Type="Int32" DefaultValue="01" />
                <asp:SessionParameter Name="StartYear" SessionField="StartYear" Type="Int32" DefaultValue="2012" />
                <asp:SessionParameter Name="EndMonth" SessionField="EndMonth" Type="Int32" DefaultValue="01" />
                <asp:SessionParameter Name="EndYear" SessionField="EndYear" Type="Int32" DefaultValue="2013" />
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:Panel ID="pnlSalesByVendor" runat="server" Width="100%" Visible="false">
        </asp:Panel>
        <asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:HinoConnectionString %>"
            ProviderName="System.Data.SqlClient" SelectCommandType="StoredProcedure" SelectCommand="spSelectPartsDashboardSalesByVendor_ForDateRange"
            runat="server">
            <SelectParameters>
                <asp:SessionParameter Name="StartMonth" SessionField="StartMonth" Type="Int32" DefaultValue="01" />
                <asp:SessionParameter Name="StartYear" SessionField="StartYear" Type="Int32" DefaultValue="2012" />
                <asp:SessionParameter Name="EndMonth" SessionField="EndMonth" Type="Int32" DefaultValue="05" />
                <asp:SessionParameter Name="EndYear" SessionField="EndYear" Type="Int32" DefaultValue="2013" />
            </SelectParameters>
        </asp:SqlDataSource>
    </div>
    </form>
</body>
</html>
Code Behind File:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Hino_BL;
using Telerik.Web.UI;
 
public partial class Dashboard_HinoPartsDashboard : System.Web.UI.Page
{
 
    #region Properties
 
    private int _LoggedInUser;
    private string _LoggedInUserName;
    private int _SecurityPage;
    private bool _IsAdmin;
 
    public int LoggedInUser
    {
        get { return _LoggedInUser; }
        set { _LoggedInUser = value; }
    }
    public string LoggedInUserName
    {
        get { return _LoggedInUserName; }
        set { _LoggedInUserName = value; }
    }
    public int SecurityPage
    {
        get { return _SecurityPage; }
        set { _SecurityPage = value; }
    }
    public bool IsAdmin
    {
        get { return _IsAdmin; }
        set { _IsAdmin = value; }
    }
    #endregion
 
    protected void rgPartDashboard_PreRender(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //rgPartDashboard.MasterTableView.Items[0].Expanded = true;
            //rgDashboard.MasterTableView.Items[0].ChildItem.FindControl("InnerContainer").Visible = true;
        }
    }
    private void DefineGridStructure()
    {
        try
        {
            string FromYearMonth = Request.Form.Get("FromMonthDropDownList");
            string ToYearMonth = Request.Form.Get("ToMonthDropDownList");
            if (FromYearMonth == null)
            {
                FromYearMonth = FromMonthDropDownList.SelectedValue;
                ToYearMonth = ToMonthDropDownList.SelectedValue;
            }
 
            RadGrid rgPartSalesByVendor = new RadGrid();
            rgPartSalesByVendor.AutoGenerateColumns = false;
            rgPartSalesByVendor.ID = "rgPartSalesByVendor";
            rgPartSalesByVendor.GridLines = System.Web.UI.WebControls.GridLines.Both;
            rgPartSalesByVendor.ShowFooter = true;
            rgPartSalesByVendor.Skin = "Outlook";
            rgPartSalesByVendor.NeedDataSource += new Telerik.Web.UI.GridNeedDataSourceEventHandler(rgPartSalesByVendor_Load);
            rgPartSalesByVendor.MasterTableView.Caption = "Sales By Vendor";
            rgPartSalesByVendor.MasterTableView.CssClass = "MasterClass";
            rgPartSalesByVendor.MasterTableView.Columns.Clear();
 
            GridBoundColumn boundColumnVendor = new GridBoundColumn();
            boundColumnVendor.DataField = "Vendor";
            boundColumnVendor.UniqueName = "Vendor";
            boundColumnVendor.HeaderText = "Vendor";
            boundColumnVendor.HeaderStyle.Font.Bold = true;
            boundColumnVendor.FooterStyle.Font.Bold = true;
            boundColumnVendor.FooterText = "Grand Total:";
            boundColumnVendor.ItemStyle.ForeColor = System.Drawing.Color.Blue;
 
 
            rgPartSalesByVendor.MasterTableView.Columns.Add(boundColumnVendor);
 
            //Bind sales By vendor Grid
            SqlDataSource1.SelectParameters["StartMonth"].DefaultValue = FromYearMonth.Substring(4, 2);
            SqlDataSource1.SelectParameters["StartYear"].DefaultValue = FromYearMonth.Substring(0, 4);
            SqlDataSource1.SelectParameters["EndMonth"].DefaultValue = ToYearMonth.Substring(4, 2);
            SqlDataSource1.SelectParameters["EndYear"].DefaultValue = ToYearMonth.Substring(0, 4);
            DataTable dt = null;
            DataView dv = null;
            dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
 
            if (dv != null)
            {
                dt = dv.ToTable();
                CreateTemplateColumn(dt, ref rgPartSalesByVendor, FromYearMonth, ToYearMonth);
            }
            pnlSalesByVendor.Controls.Add(rgPartSalesByVendor);
 
            Session.Add("GridPartSalesByVendor", rgPartSalesByVendor);
        }
        catch (Exception e)
        {
            Response.Write("Error has occured in DefineGrid structure" + e.Message);
        }
 
    }
    protected void Page_Init(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitializeMonthDropDownLists();
        }
        DefineGridStructure();
 
    }
 
    protected void Page_Load(object sender, EventArgs e)
    {
        //get the logged in user
        //this will work on local dev machine and prod without a change
        if (Request.Url.AbsoluteUri.ToString().Contains("localhost"))
            LoggedInUserName = "bbajwa";
        //LoggedInUserName = "braddpm";
        else
            LoggedInUserName = Request.Cookies["UserName"].Value.ToString();
 
        //verify that they can access this page.
        check_Security();
 
        if (!IsPostBack)
        {
 
 
            try
            {
                Hino_BL.HinoCommons getRefresh = new Hino_BL.HinoCommons();
                lblLastRefreshDate.Text = "Last Refresh Date: " + Convert.ToDateTime(getRefresh.GetConfigVariableFromDatabase("AS400", "LastDashboardRefreshDate")[0].VariableValue.ToString());
            }
            catch
            {
                lblLastRefreshDate.Text = "Last Refresh Date: N/A";
            }
        }
        try
        {
            RadGrid grid = (RadGrid)pnlSalesByVendor.FindControl("rgPartSalesByVendor");
 
            RadAjaxManager1.AjaxSettings.Clear();
            RadAjaxManager1.AjaxSettings.AddAjaxSetting(FromMonthDropDownList, pnlSalesByVendor, RadAjaxLoadingPanel1);
            RadAjaxManager1.AjaxSettings.AddAjaxSetting(FromMonthDropDownList, pnlSalesParts, RadAjaxLoadingPanel1);
            RadAjaxManager1.AjaxSettings.AddAjaxSetting(FromMonthDropDownList, grid, RadAjaxLoadingPanel1);
        }
        catch (Exception ex)
        {
            Response.Write("Error has occured in updating Ajax" + ex.Message);
        }
 
        if (chkVendor.Checked)
        {
            pnlSalesParts.Visible = false;
            pnlSalesByVendor.Visible = true;
        }
        if (chkDealer.Checked || (chkDealer.Checked & chkVendor.Checked))
        {
            pnlSalesParts.Visible = true;
            pnlSalesByVendor.Visible = false;
        }
        if (!chkDealer.Checked & !chkVendor.Checked)
        {
            pnlSalesParts.Visible = true;
            pnlSalesByVendor.Visible = false;
        }
 
 
 
    }
    public void InitializeMonthDropDownLists()
    {
        Int32 offset = -12;
        while (offset <= 0)
        {
            FromMonthDropDownList.Items.Add(new ListItem(string.Format("{0:MMMM} {0:yyyy}", DateTime.Today.AddMonths(offset)), string.Format("{0:yyyy}{0:MM}", DateTime.Today.AddMonths(offset))));
            ToMonthDropDownList.Items.Add(new ListItem(string.Format("{0:MMMM} {0:yyyy}", DateTime.Today.AddMonths(offset)), string.Format("{0:yyyy}{0:MM}", DateTime.Today.AddMonths(offset))));
            offset += 1;
        }
 
        try
        {
            if (Session["FromMonth"].ToString() != "")
            {
                FromMonthDropDownList.Items.FindByValue(Session["FromMonth"].ToString()).Selected = true;
            }
            else
            {
                FromMonthDropDownList.SelectedIndex = 12;
            }
 
            if (Session["ToMonth"].ToString() != "")
            {
                ToMonthDropDownList.Items.FindByValue(Session["ToMonth"].ToString()).Selected = true;
            }
            else
            {
                ToMonthDropDownList.SelectedIndex = 12;
 
            }
        }
        catch
        {
            FromMonthDropDownList.SelectedIndex = 12;
            ToMonthDropDownList.SelectedIndex = 12;
        }
    }
    protected void MonthDropDownList_SelectedIndexChanged(object source, EventArgs e)
    {
 
        string FromYearMonth = FromMonthDropDownList.SelectedValue;
        string ToYearMonth = ToMonthDropDownList.SelectedValue;
        try
        {
 
            SqlDataSource3.SelectParameters["StartMonth"].DefaultValue = FromYearMonth.Substring(4, 2);
            SqlDataSource3.SelectParameters["StartYear"].DefaultValue = FromYearMonth.Substring(0, 4);
            SqlDataSource3.SelectParameters["EndMonth"].DefaultValue = ToYearMonth.Substring(4, 2);
            SqlDataSource3.SelectParameters["EndYear"].DefaultValue = ToYearMonth.Substring(0, 4);
            rgPartDashboard.DataSource = SqlDataSource3;
 
            //Bind sales By vendor Grid
            SqlDataSource1.SelectParameters["StartMonth"].DefaultValue = FromYearMonth.Substring(4, 2);
            SqlDataSource1.SelectParameters["StartYear"].DefaultValue = FromYearMonth.Substring(0, 4);
            SqlDataSource1.SelectParameters["EndMonth"].DefaultValue = ToYearMonth.Substring(4, 2);
            SqlDataSource1.SelectParameters["EndYear"].DefaultValue = ToYearMonth.Substring(0, 4);
            RadGrid grid = (RadGrid)pnlSalesByVendor.FindControl("rgPartSalesByVendor");
            grid.DataSource = SqlDataSource1;
            grid.Rebind();
        }
        catch (Exception ex)
        {
            Response.Write("Error has occured:" + ex.Message);
        }
 
        Session.Add("FromMonth", FromMonthDropDownList.SelectedValue);
        Session.Add("ToMonth", ToMonthDropDownList.SelectedValue);
 
        if (rgPartDashboard.Visible)
        {
            rgPartDashboard.Rebind();
        }
 
    }
 
    protected void btnExport_Click(object sender, System.EventArgs e)
    {
 
        RadGrid grid = (RadGrid)pnlSalesByVendor.FindControl("rgPartSalesByVendor");
        if (grid.Visible)
        {
            grid.MasterTableView.ExportToExcel();
        }
        if (rgPartDashboard.Visible)
        {
            ConfigureExport();
            rgPartDashboard.MasterTableView.ExportToExcel();
        }
 
    }
 
    public void ConfigureExport()
    {
        rgPartDashboard.ExportSettings.ExportOnlyData = chk1.Checked;
        rgPartDashboard.ExportSettings.IgnorePaging = chk2.Checked;
        rgPartDashboard.ExportSettings.OpenInNewWindow = chk3.Checked;
        if (chk4.Checked)
        {
            rgPartDashboard.ExportSettings.IgnorePaging = false;
            foreach (Telerik.Web.UI.GridDataItem item in rgPartDashboard.MasterTableView.Items)
            {
                item.Expanded = true;
 
                foreach (Telerik.Web.UI.GridDataItem nestedItem in item.ChildItem.NestedTableViews[0].Items)
                {
                    nestedItem.Expanded = true;
                    //foreach (Telerik.Web.UI.GridDataItem nestedItem1 in nestedItem.ChildItem.NestedTableViews[0].Items)
                    //{
                    //    nestedItem1.Expanded = true;
                    //}
                }
            }
        }
    }
 
 
    protected void rgPartDashboard_Load(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        if (!e.IsFromDetailTable)
        {
 
            string FromYearMonth = FromMonthDropDownList.SelectedValue;
            string ToYearMonth = ToMonthDropDownList.SelectedValue;
            try
            {
 
                SqlDataSource3.SelectParameters["StartMonth"].DefaultValue = FromYearMonth.Substring(4, 2);
                SqlDataSource3.SelectParameters["StartYear"].DefaultValue = FromYearMonth.Substring(0, 4);
                SqlDataSource3.SelectParameters["EndMonth"].DefaultValue = ToYearMonth.Substring(4, 2);
                SqlDataSource3.SelectParameters["EndYear"].DefaultValue = ToYearMonth.Substring(0, 4);
                rgPartDashboard.DataSource = SqlDataSource3;
            }
            catch (Exception ex)
            {
                Response.Write("Error has occured in rgPartDashboard_Load" + ex.Message);
            }
 
        }
    }
    protected void rgPartDashboard_Detail(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
    {
        string FromYearMonth = FromMonthDropDownList.SelectedValue;
        string ToYearMonth = ToMonthDropDownList.SelectedValue;
        try
        {
 
            Telerik.Web.UI.GridDataItem dataItem = (Telerik.Web.UI.GridDataItem)e.DetailTableView.ParentItem;
 
            SqlDataSource2.SelectParameters["userid"].DefaultValue = dataItem.GetDataKeyValue("user_id").ToString();
 
            SqlDataSource2.SelectParameters["StartMonth"].DefaultValue = FromYearMonth.Substring(4, 2);
            SqlDataSource2.SelectParameters["StartYear"].DefaultValue = FromYearMonth.Substring(0, 4);
            SqlDataSource2.SelectParameters["EndMonth"].DefaultValue = ToYearMonth.Substring(4, 2);
            SqlDataSource2.SelectParameters["EndYear"].DefaultValue = ToYearMonth.Substring(0, 4);
            (source as Telerik.Web.UI.RadGrid).DataSource = SqlDataSource2;
        }
        catch (Exception ex)
        {
            Response.Write("Error has occured in rgPartDashboard_Detail:" + ex.Message);
        }
    }
    protected string GetDPMPlusDealer(string DMPName, string DealerName)
    {
        return DMPName + ", " + DealerName;
    }
    protected void rgPartSalesByVendor_Load(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        if (!e.IsFromDetailTable)
        {
 
            string FromYearMonth = FromMonthDropDownList.SelectedValue;
            string ToYearMonth = ToMonthDropDownList.SelectedValue;
            try
            {
                SqlDataSource1.SelectParameters["StartMonth"].DefaultValue = FromYearMonth.Substring(4, 2);
                SqlDataSource1.SelectParameters["StartYear"].DefaultValue = FromYearMonth.Substring(0, 4);
                SqlDataSource1.SelectParameters["EndMonth"].DefaultValue = ToYearMonth.Substring(4, 2);
                SqlDataSource1.SelectParameters["EndYear"].DefaultValue = ToYearMonth.Substring(0, 4);
                (source as Telerik.Web.UI.RadGrid).DataSource = SqlDataSource1;
            }
            catch (Exception ex)
            {
                Response.Write("Error has occured in rgPartSalesByVendor_Load:" + ex.Message);
            }
 
        }
    }
    #region Create GridTemplate column
    private void CreateTemplateColumn(DataTable dt, ref RadGrid rg, string FromYearMonth, string ToYearMonth)
    {
        foreach (DataColumn dc in dt.Columns)
        {
            if (dc.ColumnName == "Vendor" || dc.ColumnName == "vendorID")
                continue;
            if (dc.ColumnName != "Vendor" && dc.ColumnName != "VendorID")
            {
                string ColName = dc.ColumnName;
                string[] DPMNameAndID = ColName.Split(';');
                string DPMName = DPMNameAndID[0];
                string DMPId = DPMNameAndID[1];
                GridTemplateColumn templateColumn = new GridTemplateColumn();
                templateColumn.ItemTemplate = new MyTemplate(ColName, FromYearMonth, ToYearMonth, DPMName, DMPId);
                templateColumn.SortExpression = ColName;
                templateColumn.HeaderText = DPMName;
                templateColumn.HeaderStyle.Font.Bold = true;
                templateColumn.FooterStyle.Font.Bold = true;
                templateColumn.FooterAggregateFormatString = "{0:F2}";
                templateColumn.DataField = ColName;
                templateColumn.Aggregate = Telerik.Web.UI.GridAggregateFunction.Sum;
                rg.MasterTableView.Columns.Add(templateColumn);
            }
        }
    }
 
    private class MyTemplate : ITemplate
    {
 
        protected HyperLink SealeByVendorTrans;
 
        private string colname;
        private string _fromDate;
        private string _toDate;
        private string _DPMName;
        private string _DPMId;
        public MyTemplate(string cName, string fromDate, string toDate, string DPMName, string DPMId)
        {
            colname = cName;
            _fromDate = fromDate;
            _toDate = toDate;
            _DPMName = DPMName;
            _DPMId = DPMId;
        }
        public void InstantiateIn(System.Web.UI.Control container)
        {
            SealeByVendorTrans = new HyperLink();
            SealeByVendorTrans.ID = colname;
            SealeByVendorTrans.DataBinding += new EventHandler(SealeByVendorTrans_DataBinding);
            container.Controls.Add(SealeByVendorTrans);
        }
        void SealeByVendorTrans_DataBinding(object sender, EventArgs e)
        {
            HyperLink link = (HyperLink)sender;
            GridDataItem container = (GridDataItem)link.NamingContainer;
            link.Text = ((DataRowView)container.DataItem)[colname].ToString();
            link.NavigateUrl = "HinoPartsDashBoardTransactions.aspx?type=Vendor&TransType=V&DPMName=" + _DPMName + "&DPM=" + _DPMId + "&from=" + _fromDate + "&to=" + _toDate + "&VendorID=" + ((DataRowView)container.DataItem)["VendorID"].ToString() + "&Vendor=" + ((DataRowView)container.DataItem)["Vendor"].ToString();
        }
    }
    #endregion
 
 
    #region Security
    public void check_Security()
    {
        Boolean HasAccess = false;
        IsAdmin = false;
 
        Hino_BL.UserSecurity userSec = new Hino_BL.UserSecurity();
        userSec.UserName = LoggedInUserName;
 
        try
        {
            UserSecurity userInfo = userSec.GetUserByUserName()[0];
            LoggedInUser = userInfo.User_id;
        }
        catch
        {
            LoggedInUser = 0;
        }
 
        userSec.SecurityPageName = "Dashboard";
 
        foreach (UserSecurity list in userSec.GetSecurityPageByName())
        {
            SecurityPage = list.SecurityPage_id;
        }
 
        userSec.SecurityPage_id = _SecurityPage;
        userSec.User_id = _LoggedInUser;
 
        foreach (UserSecurity list in userSec.GetSecurityFunctionsByUser_idandSecurityPage_id())
        {
            HasAccess = true;
        }
 
        //if they don't have access take them to the access denied page.
        if (!HasAccess)
        {
            Response.Redirect("../AccessDenied.aspx");
        }
    }
    #endregion
 
 
}

6 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 28 May 2013, 11:59 AM
Hello,

The problem most probably comes from the fact that you are invoking the DefineGridStructure method on each postback. Try to put it inside the IsPostBack clause and you should get rid off the columns.

Additionally, please note that you should either create all columns programmatically or you should leave all the columns declaratively. Disregarding this suggestion may result in erroneous behavior in some scenarios.

You could find more information about the programmatic creation of RadGrid structure in this help topic.

Regards,
Andrey
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
John
Top achievements
Rank 1
answered on 16 Jul 2013, 06:04 PM
Could you be more specific what you mean by "erroneous behavior in some scenarios" in your comment "Disregarding this suggestion [either create all columns programmatically or you should leave all the columns declaratively] may result in erroneous behavior in some scenarios." Thanks
0
Andrey
Telerik team
answered on 17 Jul 2013, 12:44 PM
Hello,

I am afraid that I could not list all the cases when something will go wrong by not following the requirements of the control, however, you could expect databinding problems, visual glitches and not persistent behavior. That is why we are describing the supported scenarios in help articles and when we are certain that some scenario is not supported we indicate that in the help topics as well.

Regards,
Andrey
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Balkar
Top achievements
Rank 1
answered on 17 Jul 2013, 12:55 PM
Hi,
 The problem is resolved by adding the line below in page_load events:
  upd1.ContentTemplateContainer.Controls.Add(divsalesdata);
upd1 is update panel, Dynamic radgrid is created in each postback and added to divsalesdata.
Please explain me if possible, why we needed to add dynamic grid to update panel.
0
Andrey
Telerik team
answered on 22 Jul 2013, 07:05 AM
Hi,

Where you will add the control depends on your scenario. If you want the dynamic implementation of RadGrid to be part of UpdatePanel then you should add the RadGrid instance to the UpdatePanel Controls collection otherwise you could add the control to the Form Controls collection.

As far for the add of the control, each control from the page should be recreated and added to its parent control in order for the ViewState to be restored correctly. When you define controls in the mark-up this is done automatically by the framework for you, however, when you define the controls manually you should take care of that.

Regards,
Andrey
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Learner
Top achievements
Rank 1
answered on 08 Oct 2014, 10:55 AM
I got rid of extra columns getting created on RadGrid's page movements(1, 2,3...) by simply setting EnableColumnsViewState = "false".

my ascx:-

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="userroles.ascx.cs" Inherits="ProvoCraft.Admin.Web.Controls.Admin.userroles" %>
<telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="grdUserRoles">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="grdUserRoles" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManagerProxy>

<asp:MultiView ID="PageView" runat="server">

    <%-- Manage/Add Material Settings --%>
    <asp:View ID="userrolesview" runat="server">
        <span style="color: White;">Manage User Roles:</span>
        <telerik:RadGrid ID="grdUserRoles" runat="server"
            AutoGenerateColumns="false"            
            AllowFilteringByColumn="true"
            AllowSorting="true"
            AllowMultiRowSelection="false"
            AllowPaging="true"
            PageSize="50"
            Width="1170px" >
            <GroupingSettings CaseSensitive="false" />
            <MasterTableView AutoGenerateColumns="false" TableLayout="Auto" ShowFooter="true" CommandItemDisplay="Top" Width="150px" EnableColumnsViewState="false">
                <CommandItemSettings ShowRefreshButton="true" ShowExportToExcelButton="false" ShowAddNewRecordButton="false" />
            </MasterTableView>
            <ClientSettings EnableRowHoverStyle="true">
                <Selecting AllowRowSelect="true" />
                <Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="false" FrozenColumnsCount="2" />
            </ClientSettings>
        </telerik:RadGrid>
    </asp:View>
</asp:MultiView>


my ascx.cs:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using System.Web.Security;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using ProvoCraft.Admin.Web.Classes.Controls;
using System.Diagnostics;
using System.Web.UI.HtmlControls;

namespace ProvoCraft.Admin.Web.Controls.Admin
{
    public partial class userroles : PCAUserControl
    {
        public string connectionString = ConfigurationManager.ConnectionStrings["Kepler"].ConnectionString;


        public void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
            }
        }

        protected void Page_Init(object sender, EventArgs e)
        {
            grdUserRoles_NeedDataSource(); //As per Telerik, Needs to be called here only. Does not work on Page Load.
        }


        public userroles()
        {
            Section.Name = "User Roles";
            Section.Url = "userroles";
            Section.SubSections.Add(new PageSection("Manage User Roles", "userroles"));
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
        }

        public void grdUserRoles_NeedDataSource()
        {
            // Note:- EnableColumnsViewState="false". This property is set in .ascx.
            //It restricts extra blank column being added to grid which will be added if this property is omitted

            var data = UserXRolesPivotAdminGetAll();
            int i = 0;            

            foreach (DataColumn dc in data.Columns)
            {
                i++;

                if (i > 2)
                {
                    GridTemplateColumn tempColumn = new GridTemplateColumn();
                    tempColumn.HeaderText = dc.ColumnName;
                    tempColumn.ItemTemplate = new GrdChkBoxTemplate(Convert.ToString(dc.ColumnName));

                    grdUserRoles.MasterTableView.Columns.Add(tempColumn);

                    
                }
                else
                {
                    GridBoundColumn boundColumn = new GridBoundColumn();
                    boundColumn.HeaderText = dc.ColumnName;
                    boundColumn.DataField = dc.ColumnName;

                    grdUserRoles.MasterTableView.Columns.Add(boundColumn);
                }

            }
            grdUserRoles.DataSource = data;

        }

        private DataTable UserXRolesPivotAdminGetAll()
        {
            var dt = new DataTable();
            SqlConnection conn = null;
            SqlDataReader reader = null;
            try
            {
                conn = new SqlConnection(connectionString);
                SqlCommand cmd = new SqlCommand("UserXRolesPivotAdminGetAll", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                conn.Open();
                reader = cmd.ExecuteReader();
                dt.Load(reader);
            }
            catch (SqlException ex)
            {
                // handle error
                Debug.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                // handle error
                Debug.WriteLine(ex.Message);
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
                if (reader != null)
                {
                    reader.Close();
                }
            }

            return dt;
        }
    }

    public class GrdChkBoxTemplate : ITemplate
    {

        private CheckBox checkBox;
        private string id;
        public GrdChkBoxTemplate(string id)
        {
            this.id = id;
        }

        public void InstantiateIn(System.Web.UI.Control container)
        {
            checkBox = new CheckBox();
            checkBox.ID = id;
            checkBox.DataBinding += checkBox_DataBinding;
            checkBox.CheckedChanged += checkBox_CheckedChanged;
            container.Controls.Add(checkBox);
        }

        private void checkBox_CheckedChanged(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        private void checkBox_DataBinding(object sender, EventArgs e)
        {
            CheckBox chk = (CheckBox)sender;
            GridDataItem container = (GridDataItem)chk.NamingContainer;
            chk.Checked = Convert.ToBoolean(((DataRowView)container.DataItem)[id]);
        }
    }
}

Tags
Grid
Asked by
Balkar
Top achievements
Rank 1
Answers by
Andrey
Telerik team
John
Top achievements
Rank 1
Balkar
Top achievements
Rank 1
Learner
Top achievements
Rank 1
Share this question
or