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

[Solved] RadGrid: Sorting issue with column of Object datatype

3 Answers 160 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Preeti
Top achievements
Rank 1
Preeti asked on 28 May 2013, 02:13 PM

Hi,

 

I have a radgrid  (radGrd) with two column Name(Type:string) and Value(Type:Object). And I am binding List of Attribute class to my radgrid

 

Private class Attribute

{

 public string Name{ get; set; }

        public Object Value{ get; set; }

}

 

The Value object mentioned above can be of type string or Integer. In my case both filtering and sorting is working successfuly with Name column. However, it is fails in case of Value. Can you please tell me what is missing in my case which is causing this issue? Here is the code snippet of the Radgrid for your reference.

<telerik:radgrid id="radGrd" allowmultirowedit="false" cellpadding="0" cellspacing="0"
    runat="server" allowsorting="true" allowfilteringbycolumn="true" allowpaging="true"
    onneeddatasource="radGrd_NeedDataSource" onitemcommand="radGrd_ItemCommand" onitemcreated="radGrd_ItemCreated"
    onupdatecommand="radGrd_UpdateCommand" ondeletecommand="radGrd_DeleteCommand"
    enableheadercontextmenu="true" groupingenabled="false" enableheadercontextfiltermenu="true"
    enablelinqexpressions="false" onitemdatabound="radGrd_ItemDataBound">
<MasterTableView AutoGenerateColumns="False" EditMode="InPlace" CommandItemDisplay="Bottom"
PageSize="10" TableLayout="Fixed" CommandItemSettings-ShowAddNewRecordButton="false"
CommandItemSettings-ShowRefreshButton="false" HeaderStyle-HorizontalAlign="Center"
HeaderStyle-Font-Bold="true" AllowFilteringByColumn="True" EnableHeaderContextMenu="true"
IsFilterItemExpanded="false">
<NoRecordsTemplate>
No records available</NoRecordsTemplate>
<PagerStyle HorizontalAlign="Right" Position="TopAndBottom" VerticalAlign="Middle"
Mode="NextPrevAndNumeric" AlwaysVisible="true" PageButtonCount="5"></PagerStyle>
<Columns>
<telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name" AllowFiltering="false" ItemStyle-HorizontalAlign="Left" ReadOnly="true" DataType="System.String" HeaderStyle-Width="90px"> </telerik:GridBoundColumn>
<telerik:GridTemplateColumn HeaderText="Value" DataField="Value"
UniqueName="Value" ItemStyle-Width="40px" AutoPostBackOnFilter="true"
HeaderStyle-Width="100px" ItemStyle-HorizontalAlign="Left" DataType="System.String">
<ItemTemplate>
<asp:Label ID="lblAttVal" runat="server" Text='<%# Bind("Value") %>'
Width="10px"></asp:Label>
</ItemTemplate>
<HeaderTemplate>
        <table>
            <tr>
                <td>
                    <asp:LinkButton ID="Sort1" runat="server" CommandArgument="Value" CommandName="Sort"
                        Text="Value"></asp:LinkButton>
                </td>
                <td>
                    <img src="Images/fillter_icon.png" style="margin-top: 5px; margin-left: 5px; cursor: pointer"
                        onclick='ShowColumnHeaderMenu(event,"Value")' alt="" />
                </td>
            </tr>
        </table>
    </HeaderTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtValue" runat="server" Text='<%# Bind("Value") %>'
Width="82px"></asp:TextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
<ClientSettings>
<Scrolling AllowScroll="True" ScrollHeight="300px" UseStaticHeaders="true"></Scrolling>
</ClientSettings>
</telerik:radgrid>



Thanks,
Preeti

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 29 May 2013, 08:51 AM
Hello Preeti,

I have tried your code,and it works fine for me,here is the code,please have a look at it.

ASPX:
<telerik:RadGrid ID="RadGrid1" AllowFilteringByColumn="true" AllowSorting="true" AutoGenerateColumns="false" runat="server">
       <MasterTableView>
           <Columns>
               <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name" AllowFiltering="false"
                   ItemStyle-HorizontalAlign="Left" ReadOnly="true" DataType="System.String" HeaderStyle-Width="90px">
               </telerik:GridBoundColumn>
               <telerik:GridTemplateColumn HeaderText="Value" DataField="Value" UniqueName="Value"
                   ItemStyle-Width="40px" AutoPostBackOnFilter="true" HeaderStyle-Width="100px"
                   ItemStyle-HorizontalAlign="Left" DataType="System.String">
                   <ItemTemplate>
                       <asp:Label ID="lblAttVal" runat="server" Text='<%# Bind("Value") %>' Width="10px"></asp:Label>
                   </ItemTemplate>
                   <HeaderTemplate>
                       <table>
                           <tr>
                               <td>
                                   <asp:LinkButton ID="Sort1" runat="server" CommandArgument="Value" CommandName="Sort"
                                       Text="Value"></asp:LinkButton>
                               </td>
                               <td>
                                   <img src="Images/fillter_icon.png" style="margin-top: 5px; margin-left: 5px; cursor: pointer"
                                      onclick='ShowColumnHeaderMenu(event,"Value")' alt="" />
                               </td>
                           </tr>
                       </table>
                   </HeaderTemplate>
                   <EditItemTemplate>
                       <asp:TextBox ID="txtValue" runat="server" Text='<%# Bind("Value") %>' Width="82px"></asp:TextBox>
                   </EditItemTemplate>
               </telerik:GridTemplateColumn>
           </Columns>
       </MasterTableView>
   </telerik:RadGrid>

C#:
protected void Page_Load(object sender, EventArgs e)
{
    ArrayList dataSource = new ArrayList();
    Value ob = new Value();
    ob.val = 1;
    Value ob1 = new Value();
    ob1.val = 2;
    dataSource.Add(new Attribute() { Name = "aaa", Value = ob.val});
    dataSource.Add(new Attribute() { Name = "bbb", Value = ob1.val });
    RadGrid1.DataSource = dataSource;     
}
 
public class Attribute
{
  public string Name{ get; set; }
  public Object Value{ get; set; }
}
public class Value
{
  public int val { get; set; }
}

Thanks,
Princy
0
Preeti
Top achievements
Rank 1
answered on 29 May 2013, 01:07 PM
Hi Princy,
 
Thanks for your inputs. I tried incorporating your logic in our application. However, it is still not working at my end. Is it possible for you to share the sample application created by you so that I could verify what is missing in my logic?

Thanks,
Preeti
0
Princy
Top achievements
Rank 2
answered on 30 May 2013, 06:38 AM
Hi Preeti,

I have given the entire code snippet above,please provide your C# code so that i may check on it and help you.

Thanks,
Princy
Tags
Grid
Asked by
Preeti
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Preeti
Top achievements
Rank 1
Share this question
or