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

Forums / Developing with Sitefinity / How to use GridView control

How to use GridView control

14 posts, 0 answered
  1. Kiran Kakanur
    Kiran Kakanur avatar
    7 posts
    Registered:
    29 Sep 2004
    02 May 2008
    Link to this post
    Hi,

    I am new to SiteFinity and I am trying to use the GridView control in one of my pages. In the GridView Properties page, I need to enter a DataSourceID. The help for this field says that it is...The Control ID of an IDataSource that will be used as the data source.

    I found the following 2 postings on your forum which instructs you to first add a Data Source and then use the ID of the Data Source as the ID of the GridView control.

    http://www.sitefinity.com/support/forums/support-forum-thread/b1043S-mgctm.aspx

    http://www.sitefinity.com/support/forums/support-forum-thread/b1043S-bcgkam.aspx/

    So I created an XML Data Source and then specified the path (C:\data.xml) to the xml file in the "DataFile" property and I then copied and pasted the ID (XMLDataSource1) in the GridView "DataSourceID" property.

    But when I attempt to preview the page, I get the following error:

    The data source for GridView with id "GridView1" did not have any properties or attributes from which to generate columns. Ensure that your data source has content.

    I am not sure what data and what format the data needs to be in the xml file that I referenced in the XML Data Source control.

    What am I missing? I have looked in the documentation, but was unable to find the solution.

    I would greatly appreciate any advice/suggestions that you can provide.

    Thanks.

    Kiran




  2. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    03 May 2008
    Link to this post
    Hi Kiran Kakanur,

    I have attached a simple xml file that you can bind to your GridView. Here are the steps you need to do:

    1. Download the file I've provided you with in attachment
    2. Unzip it and put the data.xml file in the root of your website
    3. Drag XML Data Source (in Data section of Toolbox) on the page
    4. Edit the XML Data Source and set the property of the DataFile to ~/data.xml (this means that the xml file you want to bind the data source to is located in the root folder of your website and it's name is data.xml)
    5. Expand the MISC section and copy the ID value (it's probably XmlDataSource1)
    6. Click I am done
    7. Drag the GridView control (in Data section of Toolbox) on the page. Make sure that you drag it below the XmlDataSource control!
    8. Click on Edit, to edit the properties of the GridView control
    9. Past the value (the one you've copied in step 5) in the DataSourceID property. (it's probably XmlDataSource1).
    10. Click I am done and preview the page.

    You will notice that each Contact node in the xml file represents a row, while each attribute of the node represents the column.

    I hope you'll find this information helpful and thank you for getting in touch with us. Let us know if you have any additional questions.

    Best wishes,
    Ivan
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Kiran Kakanur
    Kiran Kakanur avatar
    7 posts
    Registered:
    29 Sep 2004
    04 May 2008
    Link to this post
    Hi Ivan,

    Thanks for the sample data.xml file and the detailed steps. It worked like a charm :-)

    The steps that you provided are for displaying data that is in an xml file in a GridView control. How do I display data that is in a table in a SQL Server 2005 database?  Can you please provide the steps or point me to a video or documentation?

    Thanks again for your prompt help. I greatly appreciate it.

    Best regards,
    Kiran
  4. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    05 May 2008
    Link to this post
    Hi Kiran Kakanur,

    first of all, I am really glad that the sample worked for you. While the controls in the Data section of toolbox come handy at times, they are quite limited at the moment in their functionality.

    If you wish to create a more complex UI with GridView and bind it to SQL Server, there are really many ways that you can do this, but probably the most simple is to create your own user control. The user control would be like any other, in Visual studio you drag GridView on the surface, you drag SqlDataSource, you bind the GridView to the data source, perform any additional logic you may need and once you are done, you simple upload the user control to Sitefinity toolbox (click on the "Upload a control" while in page edit mode).

    I think this would be the most simple way to bind GridView (or RadGrid) to SQL Server data.

    Let us know if we can assist you with anything else and thank you for getting in touch with us.

    Sincerely yours,
    Ivan
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. Aparna
    Aparna avatar
    20 posts
    Registered:
    05 Sep 2012
    14 Mar 2011
    Link to this post
    Hi iam very new to sitefinity
    iam trying to implement a grid veiw with xml data source when i drag  a grid The following Error is shown:

    Object does not match target type.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Reflection.TargetException: Object does not match target type.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [TargetException: Object does not match target type.]
       System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target) +9355927
       System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +100
       System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +28
       System.SecurityUtils.MethodInfoInvoke(MethodInfo method, Object target, Object[] args) +163
       System.ComponentModel.ReflectPropertyDescriptor.GetValue(Object component) +109
    
    [TargetInvocationException: Property accessor 'NegativeStyle' on object 'Telerik.Web.UI.GridHeaderContextMenu' threw the following exception:'Object does not match target type.']
       System.ComponentModel.ReflectPropertyDescriptor.GetValue(Object component) +400
       Telerik.Sitefinity.Modules.Pages.Web.Services.WcfPropertyManager.AddPropertiesRecursively(Object instance, IList`1 list, List`1 propertyDescriptorHierarchy, ControlData controlData, Int32 depth, CultureInfo culture) +208
       Telerik.Sitefinity.Modules.Pages.Web.Services.WcfPropertyManager.AddPropertiesRecursively(Object instance, IList`1 list, List`1 propertyDescriptorHierarchy, ControlData controlData, Int32 depth, CultureInfo culture) +367
       Telerik.Sitefinity.Modules.Pages.Web.Services.WcfPropertyManager.AddPropertiesRecursively(Object instance, IList`1 list, List`1 propertyDescriptorHierarchy, ControlData controlData, Int32 depth, CultureInfo culture) +367
       Telerik.Sitefinity.Modules.Pages.Web.Services.WcfPropertyManager.GetProperties(Object instance, ControlData controlData, Int32 depth, String parentPropertyPath, CultureInfo culture) +253
       Telerik.Sitefinity.Web.UI.PropertyEditor.GetPropertyBag() +145
       Telerik.Sitefinity.Web.UI.PropertyEditor.GetScriptDescriptors() +716
       System.Web.UI.ScriptControlManager.RegisterScriptDescriptors(IScriptControl scriptControl) +126
       Telerik.Sitefinity.Web.UI.AjaxDialogBase.Render(HtmlTextWriter writer) +103
       System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +65
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +268
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +26
       System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +208
       System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +9
       System.Web.UI.Control.Render(HtmlTextWriter writer) +10
       System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +65
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +268
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +26
       System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +208
       System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +177
       System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +31
       System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +312
       System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +65
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +268
       System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +53
       System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +208
       System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +9
       System.Web.UI.Page.Render(HtmlTextWriter writer) +30
       System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +65
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +268
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +26
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +8604
    


    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1


    please help  at the earlist.

    Regards,
    Aparna
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    14 Mar 2011
    Link to this post
    Hello Aparna,

    1. It looks like you are using Sitefinity 4.0, not Sitefinity 3.x
    2. It looks like you are using RadGrid control for ASP.NET AJAX, not Grid view.

    Can you tell me whether the above two statements are true and how did you bind your control. I see that the problem comes from the context menu when we are trying to get the control properties through reflection and there are some know issues with the RadGrid when you put it in the context of Sitefinity 4.0.

    All the best,
    Ivan Dimitrov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  7. Aparna
    Aparna avatar
    20 posts
    Registered:
    05 Sep 2012
    14 Mar 2011
    Link to this post
    Hi ivan,

    Thank you for your Reply,

    You statement are true. i am using sitefinity4.0 and rad control.

    Please HElp.
    How to use the Data Sources.
    I am starter. I want to know how to Connect database.

    Regards,
    Aparna
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    17 Mar 2011
    Link to this post
    Hi Aparna,

    Create a user or custom control and there bind the RadGrid. Here is a sample code

    <telerik:RadGrid ID="RadGrid1" Skin="Office2007" ShowGroupPanel="True" ShowStatusBar="true"
      runat="server"  Width="95%" AutoGenerateColumns="False"
      PageSize="3" AllowSorting="True" AllowMultiRowSelection="False" AllowPaging="True"
      GridLines="None">
      <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
      <MasterTableView Width="100%" DataKeyNames="Id"
        AllowMultiColumnSorting="True" EnableHeaderContextMenu="true" TableLayout="Fixed">
        <Columns>
          <telerik:GridBoundColumn SortExpression="Id" HeaderText="Id" DataField="Id"
            UniqueName="Id">
          </telerik:GridBoundColumn>
        </Columns>
      </MasterTableView>
    </telerik:RadGrid>

    var ds = App.WorkWith().NewsItems().Get().ToList();
    this.RadGrid1.DataSource = ds;
    RadGrid1.DataBind();


    Best wishes,
    Ivan Dimitrov
    the Telerik team
  9. Aparna
    Aparna avatar
    20 posts
    Registered:
    05 Sep 2012
    18 Mar 2011
    Link to this post
    Thank you Ivan it help.

    But i want to use the radcontorl present in project manager and bind it.

    Regards,
    Aparna
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    18 Mar 2011
    Link to this post
    Hello Aparna,

    This is the same control. Actually most of the RadControls are disabled by default from the toolbox in SP1 release.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
  11. Aparna
    Aparna avatar
    20 posts
    Registered:
    05 Sep 2012
    18 Mar 2011
    Link to this post
    Hi!

    Ok how it did it get resolved.

    Please send any tutorial if any.

    Regards,
    Aparna
  12. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    18 Mar 2011
    Link to this post
    Hi Aparna,

    Please take a look at

    • http://www.telerik.com/help/aspnet-ajax/grid-overview.html
    • http://www.sitefinity.com/40/help/developers-guide/introduction.html

    All the best,
    Ivan Dimitrov
    the Telerik team
  13. Aparna
    Aparna avatar
    20 posts
    Registered:
    05 Sep 2012
    23 Mar 2011
    Link to this post
    hi!

    How to define custom work flow in SiteFinity 4.0

    There is no option shown to upload custom work flow please send me any sample work flow

    Regards
    Aparna
  14. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
Register for webinar
14 posts, 0 answered