RadGrid Binding with datatable

7 posts, 0 answers
  1. anna
    anna avatar
    17 posts
    Member since:
    Apr 2008

    Posted 01 May 2008 Link to this post

    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.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 01 May 2008 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 02 May 2008 Link to this post

    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
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 02 May 2008 Link to this post

    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.
  6. anna
    anna avatar
    17 posts
    Member since:
    Apr 2008

    Posted 02 May 2008 Link to this post

    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.

  7. Prangadj
    Prangadj avatar
    174 posts
    Member since:
    Jan 2008

    Posted 04 May 2008 Link to this post

    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
  8. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 04 May 2008 Link to this post

    Hi Anna,

    Go through the following help document link.
    Column types

    Thanks
    Shinu.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017