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

Problem with Sorting...

3 Answers 37 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sophie
Top achievements
Rank 1
Sophie asked on 14 Sep 2009, 02:07 PM
Hi, I would like just basic sorting, but I don't know why, but I don't see link and image, and does't not work...

 <telerik:RadGrid ID="radGridUsers"
                    AllowAutomaticUpdates="False"
                    AllowAutomaticDeletes="False"
                    AutoGenerateColumns="False"
                    AllowPaging="True"
                    AllowSorting="True"
                    GridLines="None"
                    runat="server"
                    AllowMultiRowSelection="True"
                    PageSize="5"
                    OnNeedDataSource="radGridUsers_NeedDataSource"
                    OnItemCommand="radGridUsers_ItemCommand"
                    OnItemCreated="radGridUsers_ItemCreated"
                    OnDataBound="radGridUsers_DataBound" Width="100%">
                    <PagerStyle Mode="NextPrevAndNumeric" />
                    <MasterTableView
                        Width="100%"
                        CommandItemDisplay="Top"                     
                        DataKeyNames="PK_Users"
                        ClientDataKeyNames="PK_Users"
                        OverrideDataSourceControlSorting="true" >
                        <CommandItemTemplate>
                            <div style="padding: 5px 5px;">
                                <asp:LinkButton ID="lnkAdd" OnClientClick="return radGridUsers_AddNewUser();" runat="server">                                    
                                    <img src="<%# GetImage("Add") %>" style="border:0px" alt="" />
                                    <asp:Label ID="Label3" runat="server" meta:resourcekey="GridViewColumn_Command_Insert"  />
                                </asp:LinkButton>
                                &nbsp;&nbsp;                        
                                <asp:LinkButton ID="lnkDelete" runat="server" CommandName="DeleteSelectedUsers">
                                    <img src="<%# GetImage("Delete") %>" style="border:0px" alt="" />
                                    <asp:Label ID="Label2" runat="server" meta:resourcekey="GridViewColumn_Command_Delete"  />                                                             
                                </asp:LinkButton>
                                &nbsp;&nbsp;
                                <asp:LinkButton ID="lnkRefresh" runat="server" CommandName="RebindGrid">
                                    <img src="<%# GetImage("Refresh") %>" style="border:0px" alt="" />
                                    <asp:Label ID="Label1" runat="server" meta:resourcekey="GridViewColumn_Command_Refresh"  />                                 
                                </asp:LinkButton>
                                &nbsp;&nbsp;
                                <asp:LinkButton ID="lnkShowColumnPhoto" runat="server" CommandName="ShowHideColumnPhoto">
                                    <asp:Label ID="Label4" runat="server" meta:resourcekey="GridViewColumn_Command_ShowHidePhoto" Text="Show/hide column photo" />
                                </asp:LinkButton>                                
                                &nbsp;&nbsp;
                                <asp:LinkButton ID="lnkSync" runat="server">
                                    
                                    <asp:Label ID="Label5" runat="server" Text="Synchronise with tavis" />
                                </asp:LinkButton>                                                                
                            </div>
                        </CommandItemTemplate>
                        <Columns>        
                            <telerik:GridBoundColumn DataField="Name" UniqueName="Name"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="BadgeCode" UniqueName="BadgeCode"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Description" UniqueName="Description"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="IsInactive" UniqueName="IsInactive"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="IsLocalUser" UniqueName="IsLocalUser"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="CardsMode" UniqueName="CardsMode"></telerik:GridBoundColumn>
                            <telerik:GridBinaryImageColumn DataField="Photo" UniqueName="Photo" ImageAlign="NotSet" ImageHeight="80px" ImageWidth="80px" ResizeMode="Fit" />
                        </Columns>
                    </MasterTableView>
                    <ClientSettings>
                        <ClientEvents
                            OnRowDblClick="radGridUsers_ClientRowDblClick"/>
                        <Selecting AllowRowSelect="True"/>
                    </ClientSettings>      
                </telerik:RadGrid>   
             </telerik:RadAjaxPanel>           

Thanks for your help...

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 15 Sep 2009, 04:29 AM
Hello Sophie,

I see from your code that you have not set the HeaderText property of the various columns in your grid. Try setting the header text of the columns and click on the header and see if it helps sort the column in the grid.

For example:
<telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name"></telerik:GridBoundColumn> 

Thanks
Princy.
0
Sophie
Top achievements
Rank 1
answered on 15 Sep 2009, 03:06 PM
Hi Princy,

with HeaderText, it's work. But I would like use Resources in ItemCreated for my HeaderText. Is it possible to use sorting with this method?

protected void radGrid1_ItemCreated(object sender, GridItemEventArgs e)
        {
            try
            {
                if (e.Item is GridHeaderItem)
                {
                    GridHeaderItem oHeaders = (GridHeaderItem)e.Item;
                    oHeaders["DeviceID"].Text = GetLocalResourceObject("GridViewColumn_DeviceID").ToString();
                    oHeaders["Name"].Text = GetLocalResourceObject("GridViewColumn_Name").ToString();
                    oHeaders["Status"].Text = GetLocalResourceObject("GridViewColumn_Status").ToString();
                    oHeaders["LockStatus"].Text = GetLocalResourceObject("GridViewColumn_LockStatus").ToString();
                }

            }
            catch (Exception ex)
            {
                Log.Error(ex, 0x007E);
                throw;
            }
        }
0
Sophie
Top achievements
Rank 1
answered on 15 Sep 2009, 05:26 PM
OK, I saw my problem...

I change just Text for LinkButton...

if (e.Item is GridHeaderItem)
                {
                    GridHeaderItem oHeaders = (GridHeaderItem)e.Item;

                    LinkButton btnDeviceId = oHeaders["DeviceID"].Controls[0] as LinkButton;
                    btnDeviceId.Text = GetLocalResourceObject("GridViewColumn_DeviceID").ToString();
                    LinkButton btnName = oHeaders["Name"].Controls[0] as LinkButton;
                    btnName.Text = GetLocalResourceObject("GridViewColumn_Name").ToString();
                    LinkButton btnStatus = oHeaders["Status"].Controls[0] as LinkButton;
                    btnStatus.Text = GetLocalResourceObject("GridViewColumn_Status").ToString();
                    LinkButton btnLockStatus = oHeaders["LockStatus"].Controls[0] as LinkButton;
                    btnLockStatus.Text = GetLocalResourceObject("GridViewColumn_LockStatus").ToString();
                }

Thanks a lot




Tags
Grid
Asked by
Sophie
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Sophie
Top achievements
Rank 1
Share this question
or