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

After Export, Automatically rebind the Grid and select 1st row in Current Page.

2 Answers 91 Views
Grid
This is a migrated thread and some comments may be shown as answers.
gc_0620
Top achievements
Rank 1
gc_0620 asked on 27 Jun 2013, 08:14 PM

Hi,

Using VS 2010 with RadControls for ASP.NET AJAX Q1 2013 SP2.

Possible after Export i.e. Radbutton (ExportToExcel) inside CommandItemTemplate, automatically Rebind the Grid and Select the 1st row in current page?

Example: Refer to attached, prior to exporting to Excel, Row with Order id 10276, Customer Id TORTU is selected.

I would like immediately after Export, row with Order Id 10269 with CustomerID WHITC from current page ( (i.e. page# 2 of entire Grid) will be automatically selected.
 
Below is my Grid Declaration as well as code.

Thanks

gc_0620
______

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManagerProxy>
    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" Width="43%" Height="16px">
    </telerik:RadAjaxPanel>
    <asp:ValidationSummary ID="ValidationSummary1" ShowMessageBox="true" ShowSummary="false"
        runat="server" />
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    </telerik:RadCodeBlock>
    <br />
    <telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" AllowPaging="True"
        AllowSorting="True" CellSpacing="0" AllowAutomaticUpdates="true" AllowAutomaticInserts="true"
        OnItemDataBound="RadGrid1_ItemDataBound" OnPreRender="RadGrid1_PreRender" DataSourceID="LinqDataSource1"
        GridLines="None" Skin="Office2010Silver" AutoGenerateEditColumn="True">
        <ClientSettings>
            <Selecting AllowRowSelect="True" />
        </ClientSettings>
        <MasterTableView AutoGenerateColumns="False" CommandItemDisplay="Top" DataSourceID="LinqDataSource1"
            DataKeyNames="OrderID">
            <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
            <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
                <HeaderStyle Width="20px"></HeaderStyle>
            </RowIndicatorColumn>
            <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
                <HeaderStyle Width="20px"></HeaderStyle>
            </ExpandCollapseColumn>
            <Columns>
                <telerik:GridBoundColumn DataField="OrderID" DataType="System.Int32" FilterControlAltText="Filter OrderID column"
                    HeaderText="OrderID" ReadOnly="True" SortExpression="OrderID" UniqueName="OrderID">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="CustomerID" FilterControlAltText="Filter CustomerID column"
                    HeaderText="CustomerID" ReadOnly="True" SortExpression="CustomerID" UniqueName="CustomerID">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="EmployeeID" DataType="System.Int32" FilterControlAltText="Filter EmployeeID column"
                    HeaderText="EmployeeID" ReadOnly="True" SortExpression="EmployeeID" UniqueName="EmployeeID">
                </telerik:GridBoundColumn>
            </Columns>
            <EditFormSettings>
                <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                </EditColumn>
            </EditFormSettings>
            <PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
            <CommandItemTemplate>
                <table align="right">
                    <tr>
                        <td>
                            <asp:CheckBox ID="CheckBox2" Text="Ignore paging (exports all pages)" runat="server">
                            </asp:CheckBox>
                        </td>
                        <td>
                            <telerik:RadButton ID="ExportToExcel" runat="server" Text="Excel Export" Skin="Office2010Silver"
                                ToggleType="CustomToggle" ForeColor="#009900" ButtonType="LinkButton" OnClick="Button_Export_To_Excel_Click">
                            </telerik:RadButton>
                        </td>
                        <td>
                            <telerik:RadButton ID="RadButtonAdd" runat="server" Text="New" ButtonType="LinkButton"
                                Skin="Office2010Silver" ToggleType="CustomToggle" ForeColor="#009900" CommandName="InitInsert">
                            </telerik:RadButton>
                        </td>
                        <td>
                            <telerik:RadButton ID="RadButtonRefresh" runat="server" Text="Refresh Grid" ButtonType="LinkButton"
                                CommandName="Rebind" Skin="Office2010Silver" ToggleType="CustomToggle" ForeColor="#009900">
                            </telerik:RadButton>
                        </td>
                    </tr>
                </table>
            </CommandItemTemplate>
        </MasterTableView>
        <PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
        <FilterMenu EnableImageSprites="False">
        </FilterMenu>
    </telerik:RadGrid>
    <asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="DataClassesDataContext"
        EntityTypeName="" Select="new (OrderID, CustomerID, EmployeeID)"
        TableName="Orders" EnableDelete="True" EnableInsert="True" EnableUpdate="True"
        Where="OrderID <= @OrderID">
        <WhereParameters>
            <asp:Parameter DefaultValue="10285" Name="OrderID" Type="Int32" />
        </WhereParameters>
    </asp:LinqDataSource>
    <br />
</asp:Content>

protected void SetGridSettings()
    {
        GridSettingsPersister LoadPersister = new GridSettingsPersister(RadGrid1);
 
        if (Session["qa_home_filter"] == null)
        {
        }
        else
        {
            string settings = (string)Session["qa_home_filter"];
 
            LoadPersister.LoadSettings(settings);
        }
    }
     
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            // BOM to Create/Maintain Current Filter Settings
            SetGridSettings();
            // BOM to Create/Maintain Current Filter Settings
 
            // BOM to Retrieve Page Index after call back from another page
            int CurrentPageIndex = 0;
             
            if (Session["DefaultCurrentPageIndex"] != null)
            {
                int.TryParse(Convert.ToString(Session["DefaultCurrentPageIndex"]), out CurrentPageIndex);
                Session["DefaultCurrentPageIndex"] = null;
            }
 
            RadGrid1.CurrentPageIndex = CurrentPageIndex;
 
           
        }
    }
 
    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
        GridSettingsPersister SavePersister = new GridSettingsPersister(RadGrid1);
        Session["qa_home_filter"] = SavePersister.SaveSettings();
        
        if (!isSelected && Session["selIndex"] != null && Session["SessionOrderid"] == null)
        //if (!isSelected && Session["selIndex"] != null)
        {
            RadGrid1.MasterTableView.Items[(int)Session["selIndex"]].Selected = true;
            Session["selIndex"] = null;
        }
        else if (!isSelected && Session["SessionOrderid"] == null && RadGrid1.MasterTableView.Items.Count > 0)
        {
            RadGrid1.MasterTableView.Items[0].Selected = true;
            //Panelotherinfo.Visible = true;
        }
        else if (!isSelected && (Session["SessionOrderid"] != null))
        {
            string curItem = Session["SessionOrderid"].ToString();
            foreach (GridItem item in RadGrid1.MasterTableView.Items)
            {
                if (item is GridDataItem)
                {
                    GridDataItem dataItem = (GridDataItem)item;
 
                    if (curItem.Equals(dataItem.OwnerTableView.DataKeyValues[dataItem.ItemIndex]["OrderID"].ToString()))
                    {
                        dataItem.Selected = true;
                        break;
                    }
                }
            }
              
            Session["SessionOrderid"] = null;
        }
 
        isSelected = false;
 
        if (rowindex > -1)
        {
            GridDataItem item = RadGrid1.Items[rowindex];
 
            item.Selected = true;
 
            rowindex = -1;
        }
    }
 
   
    bool isSelected;
    int rowindex = -1;
 
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && e.Item.IsInEditMode) // Common for all: Insert/Edit/Preview in Main Client
        {
            if (!e.Item.OwnerTableView.IsItemInserted)
            {
                Session["selIndex"] = e.Item.ItemIndex;
            }
            e.Item.Selected = true;
            isSelected = true;
        }
    }
   
    protected void Button_Export_To_Excel_Click(object sender, System.EventArgs e)
    {
        ConfigureExport();
        RadGrid1.Rebind();
     
        RadGrid1.ExportSettings.Excel.Format = GridExcelExportFormat.Biff;
 
        //RadGrid1.MasterTableView.ExportToExcel();
 
        RadGrid1.MasterTableView.ExportToExcel();
    }
 
    public void ConfigureExport()
    {
        foreach (GridFilteringItem filter in RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem))
        {
            filter.Display = false;
        }
        RadGrid1.ExportSettings.ExportOnlyData = true;
 
        RadGrid1.ExportSettings.OpenInNewWindow = true;
 
        GridItem commandItem = RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0];
        CheckBox Check_Box2 = (CheckBox)commandItem.FindControl("CheckBox2");
 
        if (Check_Box2.Checked)
            RadGrid1.AllowPaging = false;
        else
            RadGrid1.AllowPaging = true;
    }


2 Answers, 1 is accepted

Sort by
0
gc_0620
Top achievements
Rank 1
answered on 01 Jul 2013, 01:27 PM
Folks,

Any feed backs/suggestions on this issue.

The 1st row will be automatically selected after Export->Manual Rebind on Command item Template RadButtonRefresh click event.

I want to automate this process i.e. after Export->Automatically rebind the Grid and select/highlight 1st row from the current page.

Thanks

gc_0620

0
Daniel
Telerik team
answered on 02 Jul 2013, 12:46 PM
Hello,

A possible way to do this is to select the item on the client as demonstrated in the example attached to this post. You just need to add the bin folder with the corresponding binary files and then open the folder as a regular website.

Regards,
Daniel
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.
Tags
Grid
Asked by
gc_0620
Top achievements
Rank 1
Answers by
gc_0620
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or