Copied to clipboard

Flag this post as spam?

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


  • Hari 21 posts 41 karma points
    Sep 19, 2011 @ 07:38
    Hari
    0

    How to add codebehind to a template?

    Hi all,

    I created two templates known as Home and products. In that i have to add codebehind for the products template. I dont know how to add code behind in umbraco. Help me....

    Thanks in advance

    Hari

  • Matthias 87 posts 173 karma points
    Sep 19, 2011 @ 08:28
    Matthias
    0

    Hi Hari,

    what about writing your codebehind in a usercontrol and inserting that as a macro in your template?
    Will this fulfill your requirements?

    Matthias

  • Hari 21 posts 41 karma points
    Sep 19, 2011 @ 08:39
    Hari
    0

    Matthias thanks for ur reply.

    I already created a codebehind for that productpage in visualstudio2008. I just want to connect that codebehind file to the producttemplate i created in umbraco.How can i do it?

  • Matthias 87 posts 173 karma points
    Sep 19, 2011 @ 08:44
    Matthias
    0

    Hi,

    have a look at this short Screencast from Tim: http://www.nibble.be/?p=12%20%28

    Matthias

  • Hari 21 posts 41 karma points
    Sep 19, 2011 @ 09:06
    Hari
    0

    Hi Matthias, 

    That example is good. i explain my case to u, i created a homepage and productspage in VS2008. In that, productpage holds a listview which is populated by the values given from the homepage.For that i written in the productpage codebehind file as follows,

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Data.Odbc;
    using System.Text;
    public partial class _Default : System.Web.UI.Page 
    {
     protected void Page_Load(object sender, EventArgs e)
     {
     string id = Page.Request.QueryString["GroupID"];
     try
     {
     OdbcConnection conn = new OdbcConnection();
     conn.ConnectionString = "Driver={MySQL ODBC 3.51 Driver};" +
     "Server=localhost;Database=myproject;uid=root;pwd=1234";
     conn.Open();
    OdbcCommand cmd = new OdbcCommand("select * from productmst2 INNER JOIN productgrp on productmst2.GroupID = productgrp.GroupID where productgrp.GroupID = '" + id + "'", conn);
    OdbcDataAdapter da = new OdbcDataAdapter(cmd);
     DataTable dt = new DataTable();
    da.Fill(dt);
     ListView2.DataSource = dt;
    ListView2.DataBind();
      }
     catch (Exception ex)
     {
     }  
     }
    }
    It works fine in VS2008. But i want to do the same in umbraco. How can i do it? is it possible to do that by usercontrol?
  • Matthias 87 posts 173 karma points
    Sep 19, 2011 @ 09:12
    Matthias
    0

    besides that i don't know where the url paramter "GroupID" is coming from, you can transfer your code to a usercontrol and it should work.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Sep 19, 2011 @ 09:14
    Dirk De Grave
    0

    Hari,

    You should move your code to a user control and add that as a macro on to your products template just as Matthias explained in earlier posts.

     

    Cheers,

    /Dirk

  • Hari 21 posts 41 karma points
    Sep 19, 2011 @ 09:21
    Hari
    0

    Thanks Matthias and Dirk. I am going to try ur suggestions...

  • Eric Herlitz 97 posts 129 karma points
    May 02, 2012 @ 00:01
    Eric Herlitz
    0

    You could try this solution https://umbracocs.codeplex.com/

    It will create exactly what you're after!

  • 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