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

Sorting Issue with TemplateColumn

3 Answers 20 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John John
Top achievements
Rank 1
John John asked on 10 Feb 2010, 11:06 AM
Hi
           I am running into an issue while sorting a template column.I assigned all of the properties which is relate to sosrting in Grid.  I managed to declare the template column as below

 

 

<telerik:GridTemplateColumn HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" HeaderStyle-Width="18%" 
HeaderText="Address1" SortExpression="Address1" DataField="Address1" UniqueName="Address1" GroupByExpression="Address1 Group By Address1" AllowFiltering="false">  
<ItemTemplate> 
<asp:Label ID="lblAddress1" runat="server"></asp:Label> 
</ItemTemplate> 
</telerik:GridTemplateColumn> 
 

I also used to retrieve the data from DB and bind the same with the label control in the ItemDataBound event of the grid. The sample coding snippet i mentioned below..

 

           if (e.Item.OwnerTableView.Name == "Sales")  
            {  
 
                if ((e.Item.ItemType == GridItemType.AlternatingItem) || (e.Item.ItemType == GridItemType.Item))  
                {  
                    DataSet dsFirms = (DataSet)Session["Sales"];  
                    DataRowCollection drLocal = dsFirms.Tables[0].Rows;  
                    System.Web.UI.WebControls.Label lblAddress1 = (System.Web.UI.WebControls.Label)e.Item.FindControl("lblAddress1");  // Address1  
                    if (iCount <= drLocal.Count)  
                    {                          
                        lblAddress1.Text = drLocal[iCount]["Address1"].ToString();                         
                    }  
                    iCount++;  
                }  
            } 

So since my project is subjected  to bind as above mentioned scenario,please guide me to soleve the problem

--Thanks In Advance

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 10 Feb 2010, 11:52 AM
Hi John,

From your code I undersatnd that you use the iCount variable to index through the datarow collection and set the text. On sorting the iCount variable  will be reset  to zero. So if you sort in the descending order the last item wil still have the data row  index  as zero,hence the column values appear the same and not sorted. You can check for the sort direction and set the iCount variable to the page size and decrement the iCount variable.


Hope this helps.

Thanks,
Princy
0
John John
Top achievements
Rank 1
answered on 10 Feb 2010, 12:14 PM
HI...
     Thanks for your reply. Otherthan binding the fields as mentioned above, is there any other way to bind the field dynamically to meet my scenario.


-Thanks
0
Tsvetoslav
Telerik team
answered on 15 Feb 2010, 01:29 PM
Hello John,

Just change your label declaration as follows:

<asp:Label ID="lblAddress1" runat="server"></asp:Label>

I hope this helps.

Regards,
Tsvetoslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
John John
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
John John
Top achievements
Rank 1
Tsvetoslav
Telerik team
Share this question
or