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

Dynamic Grid's Sorting

3 Answers 98 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Saurabh
Top achievements
Rank 1
Saurabh asked on 25 Jul 2012, 02:50 PM
Hi , i am using Q1 2011 version of rad control in the application

I am trying to create a Grid dynamically and implementing sorting on that  (Grid Getting Disintegratesd on sorting{unwanted empty columns appear}):

Html Code:

<telerik:RadGrid ID="rdGrd" runat="server" AutoGenerateColumns="False" EnableEmbeddedSkins ="false" Skin="Outlook" HeaderStyle-HorizontalAlign="Left" CssClass="RadGrid_Outlook"
GridLines="Both" Height="350px" AllowSorting = "true">  

<MasterTableView ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" FilterItemStyle-HorizontalAlign="Left">

 <Columns>  

<telerik:GridBoundColumn DataField="ID" Display="False" UniqueName="ID"> <ItemStyle HorizontalAlign="Left" />  </telerik:GridBoundColumn

<telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name">

 <ItemStyle HorizontalAlign="Left" />

 </telerik:GridBoundColumn>

 </Columns>

 </MasterTableView>

<ClientSettings EnableRowHoverStyle="false">
<Selecting AllowRowSelect="false" />
<Scrolling AllowScroll="true" SaveScrollPosition="true" UseStaticHeaders = "true" /> </ClientSettings>
</telerik:RadGrid>

Vb Code On page load : (DtWrAra is a datatable)

 

Private Sub AddDynamicColumns()

For c As Integer = 0 To DtWrAra.Count - 1
Dim cbDownload As New GridTemplateColumn()

cbDownload.HeaderText = DtWrAra(c).Name

cbDownload.UniqueName = DtWrAra(c).Id

cbDownload.ItemTemplate = New RadGridCheckBoxTemplate(DtWrAra(c).Id) 

Me.rdGrd.MasterTableView.Columns.Add(cbDownload)
Next
End Sub
 

 

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
rdGrd.DataSource = SampleDataSourceObject
AddDynamicColumns()

rdGrd.DataBind()

End Sub

========
These check box template columns are later checked on eachrow basis.

When i am performing sorting operation grid getting distorted .I am not Certain about the cause. Attached a screen shot..
If any one can help me on this ...

Thanks,
Saurabh

 

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 26 Jul 2012, 06:36 AM
Hi,

RadGrid does not support mixing declarative grid columns with grid columns added dynamically at runtime. You should either create all the columns in the grid programmatically, or else define them all in the ASPX file.You can find out the same mentioned in this help document.

Thanks,
Shinu.
0
Saurabh
Top achievements
Rank 1
answered on 26 Jul 2012, 06:50 AM
HI shinu,

But , I have got every thing working fine with this grid except appearence of extra blank columns while sorting.Can we do something to remove these extra blank columns appearing.

Thanks ,
Saurabh
0
Shinu
Top achievements
Rank 2
answered on 27 Jul 2012, 04:54 AM
Hi Saurabh,

The sorting causes postback. So when ever you sort, the Page_Load event is called  and it calls a function 'AddDynamicColumn'. I think this is the reason for creating extra blank spaces.But if you populate the grid and call the 'AddDynamicColumn' function inside If(!IsPostBack) in the Page_Load or inside NeedDataSource, the blank column wont show but the data inside the Column will not be shown after sorting. So better add columns either dynamically or declaratively.

Thanks,
Shinu.
Tags
Grid
Asked by
Saurabh
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Saurabh
Top achievements
Rank 1
Share this question
or