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

RadGrid Binding with datatable

6 Answers 134 Views
Grid
This is a migrated thread and some comments may be shown as answers.
anna
Top achievements
Rank 1
anna asked on 01 May 2008, 11:00 PM
I have placed a RadGrid in my pageview and I created a datable in my codebehind file and binded it with RadGrid. It displays the data. But problem is that I have to allow sorting for my first column only. How do I do that in my codebehind file.

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 02 May 2008, 04:16 AM
Hi Anna,

Try the following code snippet to enable Sorting for a column.

CS:
  protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)  
    {  
        if (e.Column is GridBoundColumn)  
        {  
            GridBoundColumn col = (GridBoundColumn)e.Column;  
            if (col.UniqueName == "Name")  
            {  
                col.AllowSorting = true;  
            }  
        }  
    } 


Princy.
0
Yavor
Telerik team
answered on 02 May 2008, 07:20 AM
Hello,

Since the ColumnCreated handler will be entered only for autogenerated columns, you can also use the RadGrid1.MasterTableView.RenderColumns collection, to get access to any of the columns in the control.

Sincerely yours,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Shinu
Top achievements
Rank 2
answered on 02 May 2008, 07:48 AM
Hi Anna,

As Yavor pointed you can enable sorting for a particular column in the PreRender event as shown below.

CS:
protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns) 
        { 
            if (col.ColumnType == "GridBoundColumn") 
            { 
                GridBoundColumn column = (GridBoundColumn)col; 
                if (column.UniqueName == "columnUniqueName") 
                { 
                    column.AllowSorting = true
                } 
            } 
        } 
        RadGrid1.Rebind(); 
      
    } 


Thanks
Shinu.
0
anna
Top achievements
Rank 1
answered on 02 May 2008, 12:46 PM
where do i put this code: my code looks like this.

Dim sku As DataColumn = New DataColumn("sku")

sku.DataType = System.Type.GetType(

"System.String")

Table1.Columns.Add(sku)

Dim Description As DataColumn = New DataColumn("Description")

Description.DataType = System.Type.GetType(

"System.String")

Table1.Columns.Add(Description)

Dim Quantity As DataColumn = New DataColumn("OrigQty")

Quantity.DataType = System.Type.GetType(

"System.String")

Table1.Columns.Add(Quantity)

Dim ShipedQty As DataColumn = New DataColumn("ShipedQty")

ShipedQty.DataType = System.Type.GetType(

"System.String")

Table1.Columns.Add(ShipedQty)

 

Dim b As Integer

b = 1

Dim row As DataRow = Table1.NewRow()

Dim a As Integer = 0

While a <= 1

row = Table1.NewRow()

Dim d As Integer
d = a

 row.Item(

"sku") = skunum(a)
row.Item("Description") = desc(a)
row.Item("OrigQty") = orig(a)

row.Item("ShipedQty") = ship(a)

Table1.Rows.Add(row)

b = b + 1

a = a + 1

End While

 

Catch ex As Exception

End Try

Dim ds As New DataSet()

ds =

New DataSet()

ds.Tables.Add(Table1)

RadGrid1.DataSource = ds

RadGrid1.DataBind()

also can you tell me how do i make my first column a hyperlink.

0
Prangadj
Top achievements
Rank 1
answered on 04 May 2008, 12:44 PM
As these guys said you have to enable the sorting feature for the first grid column attaching the ColumnCreated or PreRender event (this is not linked to the actual source data table you generate). Also use advanced binding with NeedDataSource event - see these examples:

http://www.telerik.com/DEMOS/ASPNET/Prometheus/Grid/Examples/Programming/NeedDataSource/DefaultCS.aspx
http://www.telerik.com/help/radcontrols/aspnet%2Dajax/?grdGettingFamiliarWithServerAPI.html

Prangadj
0
Princy
Top achievements
Rank 2
answered on 05 May 2008, 04:36 AM
Hi Anna,

Go through the following help document link.
Column types

Thanks
Shinu.
Tags
Grid
Asked by
anna
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Yavor
Telerik team
Shinu
Top achievements
Rank 2
anna
Top achievements
Rank 1
Prangadj
Top achievements
Rank 1
Share this question
or