Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • J M 2 posts 22 karma points
    May 30, 2014 @ 19:22
    J M
    0

    Displaying data with user control

    I am not sure if this is the right place to post this so let me know if I need to move.I am completely new to Umbraco.  I am a .net developer and have been asked at my company to evaluate CMS options for a site redesign.  We have a current site that uses a SQL Server database and we are giving it a major rehaul.Right now I just want to prove that I can retrieve some data out of our existing db and display it using Umbraco.  So I want to know if I can just create a usercontrol in vs that has a gridview on it with and is databound using a stored procedure in the database.Is this possible?  I see some videos about Nodes, etc. But do I have to do all that?  Can't I just put the usercontrol in and tell it to bind?

  • Nicholas Westby 2005 posts 6843 karma points c-trib
    May 30, 2014 @ 19:48
    Nicholas Westby
    0

    Yes, you can. Give it a try.

    Note that Umbraco 7 is capable of displaying both MVC views and ASP.NET web forms pages. It may be configured to create MVC views by default, so if that happens refer to "defaultRenderingEngine" on http://our.umbraco.org/documentation/Using-Umbraco/Config-files/umbracoSettings/

    By the way, if you do end up going with MVC, the equivalent to a usercontrol would be a partial view.

    Umbraco also has the ability to encapsulate either a usercontrol or partial view into what is called a "macro", but that is not actually necessary (i.e., you can use usercontrols and partials views like on any ASP.NET project).

  • J M 2 posts 22 karma points
    May 30, 2014 @ 20:40
    J M
    0

    Thank you.  Is there documentation on this. I am not using MVC.  I have tried the simple Hello World example for a user control using a macro but if there is a way to not use the macro that would be interesting.

    Is there documentation on how to get the data bound user control working?  I didn't find any.

     

    -Jennifer

  • Nicholas Westby 2005 posts 6843 karma points c-trib
    May 31, 2014 @ 02:57
    Nicholas Westby
    0

    For example, your template (an ASP.NET WebForms masterpage) would look something like this:

    <%@ Master Language="C#" MasterPageFile="~/umbraco/masterpages/default.master" AutoEventWireup="true" %>
    <%@ Register Src="~/UserControls/TestControl.ascx" TagPrefix="uc1" TagName="TestControl" %>
    
    <asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
        <uc1:TestControl runat="server" id="TestControl" />
    </asp:Content>
    

    And your user control would look something like this:

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TestControl.ascx.cs" Inherits="WebApplication6.UserControls.TestControl" %>
    <%
        lvTest.DataSource = new List<string>() {"a", "b", "c"};
        lvTest.DataBind();
    %>
    
    <asp:ListView runat="server" ID="lvTest">
        <ItemTemplate>
            <%# Container.DataItem.ToString() %>
        </ItemTemplate>
    </asp:ListView>
    

    Take care to change the namespaces and such. If "CodeBehind" doesn't work, maybe try "CodeFile".

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies