1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Grid View Datasource

Grid View Datasource

3 posts, 0 answered
  1. Frank
    Frank avatar
    25 posts
    Registered:
    14 Jul 2008
    12 Aug 2008
    Link to this post
    I know this is probably a silly question for most of you, but how do I connect a Grid View control to a table in a database? I am used to using AccessDataSource, but where do I put this control when using Sitefinity? In what file does it go into?

    Thanks!
  2. Frank
    Frank avatar
    25 posts
    Registered:
    14 Jul 2008
    13 Aug 2008
    Link to this post
    I figured this out, I just put the SqlDataSource control into my template.

    But how do I handle it if I set AutoGenerateColumns to false?
  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    14 Aug 2008
    Link to this post
    Hi Frank,

    If you want to have greater control over the way data is displayed, then you have to set the AutoGenerateColumns property to false, instead of letting the GridView control automatically generate the column fields, and then creating a custom Columns collection. Just to let you know the column names in DataField should be the same as your database column names, otherwise you will get a blank page or error. For more information please refer to MSDN autogeneratecolumns

    Here is a simple example:

    <asp:GridView ID="GridView1" DataSourceID="SqlDataSource" runat="server" AutoGenerateColumns="False">  
        <columns>  
           <asp:BoundField DataField="" HeaderText="" />                    
           <asp:BoundField DataField="" HeaderText="" />               
        </columns>           
    </asp:gridview>  

    Let us know if this works for you.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Register for webinar
3 posts, 0 answered