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

Set page based on external event

3 Answers 60 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 28 Jan 2011, 11:12 PM
I am running into the following scenario.

I have a combobox and a rad grid on a page.  When a value is selected in the combobox I wan to highlight the associated item in the grid.  The associated item could be on any page on the grid so the focus will need to be on the correct page and then item on the page.

I could programatically page through the pages to find and select the item but was wondering if there was an inbuilt way in the grid.

3 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 02 Feb 2011, 01:46 PM
Hi John,

RadGrid does not provide such a mechanism for paging through all available pages. As you already mentioned the way is to programmatically achieve this.


Regards,
Maria Ilieva
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
John
Top achievements
Rank 1
answered on 02 Feb 2011, 03:42 PM

I am trying the following code but it steps though the records on page 1 even after the page is changed.  What am I missing

For i = 0 To radGridItems.PageCount - 1
                radGridItems.MasterTableView.CurrentPageIndex = i
                For Each grItem As GridDataItem In radGridItems.Items
                    If grItem("Item_ID").Text = Session("EditItemID") Then
                        grItem.Selected = True
                        Exit Sub
                    End If
  
                Next
  Next
<telerik:RadGrid ID="radGridItems" runat="server" 
        AllowPaging="True"  GridLines="None"   width="275"
         AllowAutomaticInserts="False" AllowAutomaticUpdates="False" AllowMultiRowEdit="false">
            <MasterTableView CommandItemDisplay="Top"   DataKeyNames="ITEM_ID" PageSize="4">
                  
                      
                             
            </MasterTableView>
            <PagerStyle Mode="NextPrev" PagerTextFormat="{4} Page {0} from {1}" ></PagerStyle>
            <ClientSettings  EnableRowHoverStyle="true" EnablePostBackOnRowClick="true">
                <Selecting AllowRowSelect="True"  />
            </ClientSettings>
  
    </telerik:RadGrid>
0
Princy
Top achievements
Rank 2
answered on 07 Feb 2011, 11:46 AM
Hello John,

Here is the sample code that I tried in application for similar scenario.Hope this helps.

ASPX:
<telerik:RadGrid ID="RadGrid1" AutoGenerateColumns="False" runat="server" DataSourceID="SqlDataSource1"
     AllowPaging="True" PageSize="3">
   <MasterTableView CommandItemDisplay="Top" DataKeyNames="EmployeeID">
       <Columns>
            <telerik:GridBoundColumn DataField="EmployeeID" UniqueName="EmployeeID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="FirstName" UniqueName="FirstName">
            </telerik:GridBoundColumn>
       </Columns>
   </MasterTableView>
</telerik:RadGrid>
 
<telerik:RadComboBox runat="server" ID="RadComboBox1" DataSourceID="SqlDataSource1"
    DataTextField="EmployeeID" DataValueField="EmployeeID" AutoPostBack="True" OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged">
</telerik:RadComboBox>

C#:
protected void RadComboBox1_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
   {
       RadComboBox combo = (RadComboBox)sender;
       RadGrid1.AllowPaging = false;
       RadGrid1.Rebind();
       int page = 0;
       int rowindex = -1;
       int pagesize = 0;
       foreach (GridDataItem item in RadGrid1.Items)
         {
           if (combo.SelectedValue == item["EmployeeID"].Text)
            {
                pagesize = RadGrid1.PageSize;
                rowindex = item.ItemIndex;
                page = (rowindex) / pagesize;
            }
         }
       RadGrid1.AllowPaging = true;
       RadGrid1.MasterTableView.CurrentPageIndex = page;
       RadGrid1.Rebind();
       RadGrid1.Items[rowindex - page*pagesize].Selected = true;
   }

Thanks,
Princy.
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
John
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or