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

Rad Grid Alphabetic Paging Insert/Edit

1 Answer 62 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shane
Top achievements
Rank 1
Shane asked on 09 Feb 2009, 03:59 PM

When using the online demo for alpahbetic paging in the Rad Grid, when I click the edit button for the 3rd record on the "P" page the grid opens the edit for the 3rd record on the "A" page.

 

 

 
The stored Procedure is basically the "SELECT * FROM [People] WHERE [Name] LIKE @Letter"

 

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
ConnectionString="<%$ ConnectionStrings:SiteSqlServer %>" 
             SelectCommand = "GetSeminarSpeakers" SelectCommandType="StoredProcedure">   
            <SelectParameters> 
                <asp:Parameter Name="Letter" DefaultValue="%" /> 
            </SelectParameters> 
         </asp:SqlDataSource> 

 Protected Sub rgSpeakers_ItemCommand(ByVal source As Object, ByVal e As Telerik.WebControls.GridCommandEventArgs) Handles rgSpeakers.ItemCommand  
 
 
        Dim value As String = Nothing 
        Select Case e.CommandName  
            Case ("alpha")  
                value = String.Format("{0}%", e.CommandArgument)  
                Exit Select  
            Case ("nofilter")  
                value = "%" 
                Exit Select  
        End Select  
   
        Me.SqlDataSource1.SelectParameters("Letter").DefaultValue = value 
        rgSpeakers.Rebind()  
 
 
    End Sub  
 
    Protected Sub rgSpeakers_ItemCreated(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles rgSpeakers.ItemCreated  
        If TypeOf e.Item Is GridPagerItem Then  
            Dim pagerItem As GridPagerItem = CType(e.Item, GridPagerItem)  
            pagerItem.PagerContentCell.Controls.Clear()  
 
            Dim i As Integer  
            For i = 65 To 65 + 25  
                Dim linkButton1 As New LinkButton  
                Dim lc As New LiteralControl("&nbsp;&nbsp;")  
                linkButton1.Text = "" + ChrW(i)  
 
                linkButton1.CommandName = "alpha" 
                linkButton1.CommandArgument = "" + ChrW(i)  
 
                pagerItem.PagerContentCell.Controls.Add(linkButton1)  
                pagerItem.PagerContentCell.Controls.Add(lc)  
            Next i  
 
            Dim lcLast As New LiteralControl("&nbsp;")  
            pagerItem.PagerContentCell.Controls.Add(lcLast)  
 
            Dim linkButtonAll As New LinkButton  
            linkButtonAll.Text = "All" 
            linkButtonAll.CommandName = "NoFilter" 
            pagerItem.PagerContentCell.Controls.Add(linkButtonAll)  
        End If  
 
    End Sub 

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 12 Feb 2009, 02:33 PM
Hello Shane,

I reviewed your code snippets. My suggestion is to save the index of the current page - in alphabetical paging this is the letter. When you try to edit, ItemCommand event is fired with command argument RadGrid.EditCommandItem. This will not be handled and so the value variable will be empty. Hence the grid is always be bound to the first page and the edit item is from the first page.

The simple solution is to add Value property which will save the value in the ViewState.

Here is a code snippet showing how to achieve this:
        public string Value  
        { 
            get  
            { 
                return (string)ViewState["Value"] ?? "%"
            } 
            set  
            { 
                ViewState["Value"] = value; 
            } 
        } 

And in the ItemCommand handler just put the Value instead of value variable:
        public void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) 
        { 
            //String value = null; 
            switch (e.CommandName) 
            {  
                case ("alpha"): 
                    { 
                        Value = string.Format("{0}%", e.CommandArgument); 
                        break
                    } 
                case ("NoFilter"): 
                    { 
                        Value = "%"
                        break
                    } 
            } 
 
            SqlDataSource1.SelectParameters["PageLetter"].DefaultValue = Value; 
            RadGrid1.Rebind(); 
        } 

Kind regards,
Georgi Krustev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Shane
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or