I started using Telerik controls for past 3 weeks…..
I am creating a Rad Grid Programmatically based on let’s say Query 2: is how many columns it is going to return from database. Query 2 results are based on Query1.
If Query 1 product type id is Q1A then Query 2 has 4 columns in it.
If Query 1 product type id is Q1B then Query 2 has 6 columns in it.
If Query 1 product type id is Q1C then Query 2 has 7 columns in it….So on.
Aspx page exactly looks like:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View ID="View1" runat="server">
' Some CONTROLS in this VIEW1
</asp:View>
<asp:View ID="View2" runat="server">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<telerik:RadGrid ID="rgvModels" runat="server" Width="950px" AutoGenerateColumns="False" Skin="SDDC" EnableEmbeddedSkins="False" AllowSorting="true">
<MasterTableView>
<Columns>
</Columns>
</MasterTableView>
<ClientSettings> <Scrolling AllowScroll="true" UseStaticHeaders="true" /> </ClientSettings> </telerik:RadGrid>
</ContentTemplate>
</asp:UpdatePanel>
</asp:View>
</ContentTemplate>
</asp:UpdatePanel>
Protected Function ProdGrid(ByVal aid As String, ByVal pid As String) As DataTable
Dim table2 As New DataTable
Dim pConn As New OracleConnection(SQLConnStr)
Dim ptID As String = String.Empty
Label3.Text = String.Empty
Dim archSQL As String = "select column1 from table 1 where id = '" & pid & "' "
Dim aConn As New OracleConnection(SQLConnStr)
aConn.Open()
Try
Dim aComm As OracleCommand = New OracleCommand(archSQL, aConn)
ptID = aComm.ExecuteScalar
Catch ex As Exception
ptID = "no data available"
End Try
If System.String.IsNullOrEmpty(ptID.ToString) Then ptID = 0
Select Case ptID
Case 1, 2
prodSQL = "select distinct c1, c2, c3 from table4 where prod='" & pid & "' order by c1"
rgvModels.MasterTableView.Columns.Clear()
' ----- column 1: -----
boundColumn = New Telerik.Web.UI.GridBoundColumn
rgvModels.MasterTableView.Columns.Add(boundColumn)
boundColumn.DataField = "c1"
boundColumn.HeaderText = "c1"
boundColumn.SortExpression = "ia"
' ----- column 2: -----
boundColumn = New Telerik.Web.UI.GridBoundColumn
rgvModels.MasterTableView.Columns.Add(boundColumn)
boundColumn.DataField = "c1"
boundColumn.HeaderText = "c2"
boundColumn.SortExpression = "c2"
' ----- column 3: -----
boundColumn = New Telerik.Web.UI.GridBoundColumn
rgvModels.MasterTableView.Columns.Add(boundColumn)
boundColumn.DataField = "c3"
boundColumn.HeaderText = "c3"
boundColumn.SortExpression = "c3"
Case 3
prodSQL = "select distinct c1, c2, c3,c4,c5 from table4
where prod='" & pid & "'order by c1"
rgvModels.MasterTableView.Columns.Clear()
' ----- column 1: -----
boundColumn = New Telerik.Web.UI.GridBoundColumn
rgvModels.MasterTableView.Columns.Add(boundColumn)
boundColumn.DataField = "c1"
boundColumn.HeaderText = "c1"
boundColumn.SortExpression = "c1"
' ----- column 2: -----
boundColumn = New Telerik.Web.UI.GridBoundColumn
rgvModels.MasterTableView.Columns.Add(boundColumn)
boundColumn.DataField = "c2"
boundColumn.HeaderText = "c2"
boundColumn.SortExpression = "c2"
' ----- column 3: -----
boundColumn = New Telerik.Web.UI.GridBoundColumn
rgvModels.MasterTableView.Columns.Add(boundColumn)
boundColumn.DataField = "c3"
boundColumn.HeaderText = "c3"
boundColumn.SortExpression = "c3"
' ----- column 4: -----
boundColumn = New Telerik.Web.UI.GridBoundColumn
rgvModels.MasterTableView.Columns.Add(boundColumn)
boundColumn.DataField = "c4"
boundColumn.HeaderText = "c4"
boundColumn.SortExpression = "c4"
' ----- column 5: -----
boundColumn = New Telerik.Web.UI.GridBoundColumn
rgvModels.MasterTableView.Columns.Add(boundColumn)
boundColumn.DataField = "c5"
boundColumn.HeaderText = "c5"
boundColumn.SortExpression = "c5"
End Select
Dim adapter As OracleDataAdapter = New OracleDataAdapter
adapter.SelectCommand = New OracleCommand(prodSQL, pConn)
pConn.Open()
adapter.SelectCommand = New OracleCommand(prodSQL, pConn)
adapter.Fill(table2)
rgvModels.DataSource = table2
Catch ex As Exception
Label3.Text = "<b class='red'>There was a problem:</b><br/>" & ex.Message.ToString
Finally
pConn.Close()
pConn.Dispose()
OracleConnection.ClearPool(pConn)
End Try
Return table2
End Function
' ----- NEEDDATASOURCE EVENT DEFINITION ----
Public
Sub rgvModels_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles rgvModels.NeedDataSource
ProdGrid(rqVal, Session(
"ProdID"))
End Sub
' ----- SORT COMMAND EVENT DEFINITION ----
Protected Sub rgvModels_SortCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridSortCommandEventArgs) Handles rgvModels.SortCommand
rgvModels.MasterTableView.SortExpressions.Clear()
ProdGrid(rqVal, Session("ProdID"))
rgvModels.DataSource = Nothing
rgvModels.Rebind()
End Sub
' ----- BUTTON CLICK EVENT DEFINITION ----
On the link button click event which actually loads the RAD grid I have following code…
' This is where product id comes from or Query 1 is based on this user clicked value
rgvModels.MasterTableView.SortExpressions.Clear()
rgvModels.DataSource = Nothing
rgvModels.Rebind()
MY QUESTION:
1) My rad grid will sort the first time very fine ascendingly.
2) If I try to click it again it will not sort again to descending order. Am I missing something here which it does not make it to sort descending?
3) I am even trying to clear sortexpressions in 3 places.
4) I saw this link
http://www.telerik.com/community/forums/aspnet-ajax/grid/how-to-clear-sorting.aspx
If this is the solution. I am sorry I don’t understand the Javascript solution to it. Leave alone the next solution by Maxim Tairov Posted on Jul 18, 2011. I definitely don’t get this.
PLEASE HELP.
Thanks,
Vidya