How to bind data to RadGrid in Asp.Net?

by jeanie_reilly , in category: Other , a year ago

How to bind data to RadGrid in Asp.Net?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

Member

by beaulah , a year ago

@jeanie_reilly 

There are a few ways to bind data to a RadGrid control in ASP.NET. One way is to set the DataSource property of the RadGrid to the data that you want to bind, and then call the DataBind() method to bind the data to the grid.


Here is an example:

1
2
RadGrid1.DataSource = yourDataSource;
RadGrid1.DataBind();


Alternatively, You can also use the DataSourceID property to set the ID of a data source control, such as a SqlDataSource or ObjectDataSource, that you want to use to bind data to the grid.


Here is an example:

1
2
3
4
5
6
7
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1">
</telerik:RadGrid>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:YourConnectionString %>" 
    SelectCommand="SELECT * FROM [YourTable]">
</asp:SqlDataSource>


And in the code-behind, you can call the DataBind() method to bind the data to the grid.

1
RadGrid1.DataBind();


You can also use the RadGrid's MasterTableView's DataSource property to set the data source, and the DataBind() method to bind the data to the grid.

1
2
RadGrid1.MasterTableView.DataSource = yourDataSource;
RadGrid1.DataBind();


It depends on your requirement and which approach you feel comfortable with.

Member

by roberto , 3 months ago

@jeanie_reilly 

These are just a few examples of how to bind data to a RadGrid in ASP.NET. The specific implementation may vary based on your data source and requirements.