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

Dynamic content for TabStrips + MultiPageView

1 Answer 11 Views
TabStrip
This is a migrated thread and some comments may be shown as answers.
Christophe
Top achievements
Rank 1
Christophe asked on 29 Jul 2019, 06:28 AM

Hi There,

Simple scenario, probably seen multiple times but couldn't find a solution for my case.

On my aspx page, I'm loading RadTabStrips along with RadMultiPage. Both are being defined from my DB, very basic, so far it's ok.

Within each pageView, I'm dynamically creating RadGrids, bound to OnNeedDataSource and OnItemCommand.

I tried multiple methods and the current one, generates the PageViews (embedding the grids) on the OnTabDataBound event from the RadTabStrip object.

Everything works like a charm until I click on some command from my Grids (refresh / export / sort whatever). When I click on any command, all of my page views disappear and I need to refresh the whole page to get them back.

How come my OnItemCommand handler is never called while OnNeedDataSource works fine (at least when it loads)? I tried to ajaxified the postback but it's not working any better. Anyone would have some recommendation ?

 

Cheers

 

Chris

 

Simple right ?

01.<div id="dataProcessingContent">
02.    <telerik:RadTabStrip ID="rtsTabs" runat="server" MultiPageID="rmpTables" SelectedIndex="0" DataSourceID="dsPageViews" DataTextField="Name" DataFieldID="ID" DataValueField="ID" OnTabDataBound="rtsTabs_TabDataBound">
03.    </telerik:RadTabStrip>
04.    <telerik:RadMultiPage ID="rmpTables" runat="server" SelectedIndex="0">
05.    </telerik:RadMultiPage>
06.</div>
07.<asp:SqlDataSource ID="dsPageViews" runat="server" SelectCommand="P_GetSomeData" SelectCommandType="StoredProcedure" ConnectionString="<% $ConnectionStrings:MyDB %>">
08.    <SelectParameters>
09.        <asp:SessionParameter SessionField="SID" DbType="Int32" DefaultValue="0" Name="sid" />
10.    </SelectParameters>
11.</asp:SqlDataSource>

 

My code behind:

001.protected void rtsTabs_TabDataBound(object sender, RadTabStripEventArgs e)
002.{
003.    try
004.    {
005.        var pv = new RadPageView();
006.        rmpTables.PageViews.Add(pv);
007.        var sdg = new SummaryDataGrid((int)Session["SID"], (string)Session["StudyName"], int.Parse(e.Tab.Value), e.Tab.Text);
008.        sdg.InstantiateIn(pv);
009. 
010.    }
011.    catch (Exception ex)
012.    {
013.        throw ex;
014.    }
015.}
016. 
017.private class SummaryDataGrid : ITemplate
018.{
019.    private int _sid;
020.    private string _studyName;
021.    private int _effortId;
022.    private string _effortName;
023.    private RadGrid _grid;
024. 
025.    public SummaryDataGrid()
026.    { }
027.    public SummaryDataGrid(int sid, string studyName, int effortId, string effortName)
028.    {
029.        this._sid = sid;
030.        this._effortId = effortId;
031.        this._effortName = effortName;
032.        this._studyName = studyName;
033.    }
034. 
035.    public void InstantiateIn(Control container)
036.    {
037.        _grid = new RadGrid();
038.        _grid.ID = $"dataGrid_{Guid.NewGuid()}";
039.        _grid.AllowMultiRowSelection = true;
040.        _grid.AllowSorting = true;
041.        _grid.AutoGenerateColumns = true;
042.        _grid.AllowFilteringByColumn = false;
043. 
044.        _grid.MasterTableView.TableLayout = GridTableLayout.Auto;
045.        _grid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
046.        _grid.MasterTableView.CommandItemSettings.ShowExportToCsvButton = true;
047.        _grid.MasterTableView.CommandItemSettings.ShowExportToExcelButton = true;
048.        _grid.MasterTableView.CommandItemSettings.ShowExportToPdfButton = true;
049.        _grid.MasterTableView.CommandItemSettings.ShowRefreshButton = true;
050.        _grid.MasterTableView.CommandItemSettings.ShowAddNewRecordButton = false;
051.        _grid.MasterTableView.CommandItemSettings.ShowCancelChangesButton = false;
052. 
053.        _grid.ExportSettings.HideStructureColumns = false;
054.        _grid.ExportSettings.IgnorePaging = true;
055.        _grid.ExportSettings.OpenInNewWindow = true;
056.        _grid.ExportSettings.ExportOnlyData = true;
057.        _grid.ExportSettings.FileName = $"Data Summary_{_studyName}_{_effortName}_{DateTime.Now.ToString("dd-MMM-yyyy")}";
058.        _grid.ExportSettings.SuppressColumnDataFormatStrings = true;
059.        _grid.ExportSettings.Excel.Format = GridExcelExportFormat.Biff;
060.        _grid.ExportSettings.Csv.ColumnDelimiter = GridCsvDelimiter.Semicolon;
061.        _grid.ExportSettings.Csv.EncloseDataWithQuotes = true;
062.        _grid.ExportSettings.Csv.FileExtension = "csv";
063.        _grid.ExportSettings.Pdf.Creator = "Me";
064.        _grid.ExportSettings.Pdf.Author = "Me";
065. 
066.        _grid.ClientSettings.EnableRowHoverStyle = true;
067.        _grid.ClientSettings.Scrolling.AllowScroll = true;
068.        _grid.ClientSettings.Scrolling.UseStaticHeaders = true;
069.        _grid.ClientSettings.Selecting.AllowRowSelect = true;
070.        _grid.ClientSettings.Resizing.AllowResizeToFit = true;
071.        _grid.ClientSettings.AllowColumnsReorder = true;
072.        _grid.ClientSettings.ReorderColumnsOnClient = true;
073.        _grid.ClientSettings.ColumnsReorderMethod = GridClientSettings.GridColumnsReorderMethod.Reorder;
074.        _grid.ClientSettings.AllowColumnHide = true;
075.        _grid.ClientSettings.ClientEvents.OnDataBound = "gridDataBound";
076. 
077.        _grid.NeedDataSource += Grid_NeedDataSource;
078.        _grid.ItemCommand += Grid_ItemCommand;
079. 
080.        container.Controls.Add(_grid);
081.    }
082. 
083.    private void Grid_ItemCommand(object sender, GridCommandEventArgs e)
084.    {
085.        try
086.        {
087.            switch (e.CommandName)
088.            {
089.                case "Refresh":
090.                    break;
091.            }
092.        }
093.        catch (Exception ex)
094.        {
095.            ex.GetDetails(Assembly.GetExecutingAssembly(), MethodBase.GetCurrentMethod().Name, MethodBase.GetCurrentMethod().DeclaringType.Name, _sid);
096.            throw ex;
097.        }
098.    }
099. 
100.    private void Grid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
101.    {
102.        try
103.        {
104.            var sda = new SqlDataAdapter("P_GetMyOtherData", new SqlConnection(MyConnectionString);
105.            sda.SelectCommand.CommandType = CommandType.StoredProcedure;
106.            sda.SelectCommand.Parameters.AddWithValue("@sid", _sid);
107.            sda.SelectCommand.Parameters.AddWithValue("@effortID", _effortId);
108. 
109.            sda.SelectCommand.Connection.Open();
110.            if (sda.SelectCommand.Connection.State != ConnectionState.Open)
111.                throw new Exception($"Woopsy... Something failed while trying to connect to DB");
112. 
113.            var data = new DataTable(this._effortName);
114.            try
115.            {
116.                sda.Fill(data);
117.            }
118.            finally
119.            {
120.                sda.SelectCommand.Connection.Close();
121.            }
122. 
123.            _grid.DataSource = data;
124.        }
125.        catch (Exception ex)
126.        {
127.            _grid.DataSource = null;
128.            ex.GetDetails(Assembly.GetExecutingAssembly(), MethodBase.GetCurrentMethod().Name, MethodBase.GetCurrentMethod().DeclaringType.Name, _sid);
129.            throw ex;
130.        }
131.    }
132.}

 

Grid_ItemCommand is never called .... ???? 

1 Answer, 1 is accepted

Sort by
0
Christophe
Top achievements
Rank 1
answered on 05 Aug 2019, 10:48 PM
Well, I just ended up not using the MultiPage control and update a single Grid on the Tab change event.... not awesome but it works.
Tags
TabStrip
Asked by
Christophe
Top achievements
Rank 1
Answers by
Christophe
Top achievements
Rank 1
Share this question
or