Michael Robbins
asked on 15 Sep 2010, 11:52 AM
Im data binding a radgrid to a datatable and creating the columns and setting them to a column in the datatable. This shows all the columns and creates the correct number of rows but doesn't bind the values from the datatable into the grid. My code is below. and see screenshot attached.
Me.uxGrid.DataSource = dt
Me.uxGrid.DataSource = dt
For Each dc In dt.Columns
gc = New GridBoundColumn
gc.HeaderText = dc.Caption
gc.UniqueName = dc.Caption
gc.DataField = dc.Caption
Me.uxGrid.MasterTableView.Columns.Add(gc)
Next
Me.uxGrid.DataBind()
5 Answers, 1 is accepted
0
Hello Michael,
Can you specify where the code for adding the grid columns is placed? Is it in the Page_Init or Page_Load event handler? Also tell us where is the grid defined, in the page markup or code behind.
Additionally, you can refer to this help article for more information on how to dynamically create RadGrid structure.
All the best,
Iana
the Telerik team
Can you specify where the code for adding the grid columns is placed? Is it in the Page_Init or Page_Load event handler? Also tell us where is the grid defined, in the page markup or code behind.
Additionally, you can refer to this help article for more information on how to dynamically create RadGrid structure.
All the best,
Iana
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
0
answered on 15 Sep 2010, 12:49 PM
Hi Grid is defined in the mark up and the code to generate columns is on the Page_PreInit.
<telerik:RadGrid ID="uxGrid" runat="server" AutoGenerateColumns="false" AllowAutomaticDeletes="false" AllowFilteringByColumn="True" AllowSorting="True" GridLines="None" Skin="Black" AllowPaging="True" Culture="en-GB" >
<MasterTableView>
<Columns>
<telerik:GridButtonColumn HeaderText="Edit" UniqueName="Edit" ItemStyle-HorizontalAlign="Center" CommandArgument="test" CommandName="Edit" ButtonType="PushButton" ButtonCssClass="Edit" Text="" HeaderStyle-Width="20px" HeaderStyle-HorizontalAlign="Center"></telerik:GridButtonColumn>
<telerik:GridButtonColumn HeaderText="Delete" UniqueName="Delete" ItemStyle-HorizontalAlign="Center" CommandArgument="test" CommandName="Delete" ButtonType="PushButton" ButtonCssClass="Delete" Text="" ConfirmText="Do you want to delete this record?" HeaderStyle-Width="20px" HeaderStyle-HorizontalAlign="Center"></telerik:GridButtonColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
0
Hello Michael,
RadGrid does not support mixing declarative and dynamic columns. You should either add all the columns in code behind or in the markup. Further more, if the grid is added declaratively on the page, columns should be added on Page_Load. If you decide to add the columns on Page_Init then the entire grid should created there.
Please refer to the previously provided help topic for further details.
Sincerely yours,
Iana
the Telerik team
RadGrid does not support mixing declarative and dynamic columns. You should either add all the columns in code behind or in the markup. Further more, if the grid is added declaratively on the page, columns should be added on Page_Load. If you decide to add the columns on Page_Init then the entire grid should created there.
Please refer to the previously provided help topic for further details.
Sincerely yours,
Iana
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
0
answered on 17 Sep 2010, 09:42 AM
How would i add these two GridButtonColumn's from the code behind?
Cheers Mike
Cheers Mike
0

Princy
Top achievements
Rank 2
answered on 17 Sep 2010, 10:18 AM
Hello Michael,
You can add the GridButtonColumns in Page_Load event like below.
VB.NET:
Thanks,
Princy.
You can add the GridButtonColumns in Page_Load event like below.
VB.NET:
Protected
Sub
Page_Load(sender
As
Object
, e
As
EventArgs)
If
Not
IsPostBack
Then
btncol.ButtonType = GridButtonColumnType.PushButton
btncol.HeaderText =
"Edit"
btncol.UniqueName =
"Edit"
btncol.CommandName =
"Edit"
Me
.uxGrid.MasterTableView.Columns.Add(btncol)
' similarly add the Delete Button
Me
.uxGrid.DataSource = dt
Dim
dc
As
DataColumn
For
Each
dc_loopVariable
As
Object
In
dt.Columns
dc = dc_loopVariable
GC =
New
GridBoundColumn()
GC.HeaderText = dc.Caption
GC.UniqueName = dc.Caption
GC.DataField = dc.Caption
Me
.uxGrid.MasterTableView.Columns.Add(GC)
Next
Me
.uxGrid.DataBind()
End
If
End
Sub
Thanks,
Princy.