Customizing user control "Edit" screen on the back

Posted by Community Admin on 04-Aug-2018 21:07

Customizing user control "Edit" screen on the backend

All Replies

Posted by Community Admin on 14-Dec-2011 00:00

I've created a user control (DirectoryListWidget.ascx) for a client that work with the Lists Module to display employee information contained in the "directory" list.  

Here's the control...

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="DirectoryListWidget.ascx.cs" Inherits="DirectoryListWidget" %>
<telerik:RadListView runat="server" ID="RadListView1" ItemPlaceholderID="ListContainer">
    <LayoutTemplate>
            <div class="sfContentBlock">
            <asp:PlaceHolder ID="ListContainer" runat="server" /></div>
    </LayoutTemplate>
    <ItemTemplate>
        <p style="margin: 0px 0px 15px 0px"><strong><asp:Literal ID="Literal1" runat="server" Text='<%# Eval("Name") %>' /></strong><br />
        <em><%# Eval("Jobtitle") %></em><br />
        2501 N. 14th Ave.<br />
        Dodge City, KS 67801<br />
        1-800-367-3222<br />
        <%=PrefixLabel %><%# Eval("Phone") %><br />
        <a href="mailto:<%# Eval("Email") %>"><%# Eval("Email") %></a></p>
    </ItemTemplate>
    <EmptyDataTemplate>
        No Data
    </EmptyDataTemplate>
</telerik:RadListView>

Here's the code behind...
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Sitefinity;
using Telerik.Sitefinity.GenericContent.Model;
using Telerik.Sitefinity.Modules.Events;
using Telerik.Sitefinity.Events.Model;
using Telerik.Web.UI;
using Telerik.Web;
using Telerik.Sitefinity.Modules.Pages;
using Telerik.Sitefinity.Taxonomies;
using Telerik.Sitefinity.Taxonomies.Model;
using System.Text.RegularExpressions;
 
 
public partial class DirectoryListWidget : System.Web.UI.UserControl
    public string DirectoryName
    
        get;
        set;
    
    public string CategoryList
    
        get;
        set;
    
    public string DepartmentList
    
        get;
        set;
    
    public string PhonePrefix
    
        get;
        set;
    
 
    public string PrefixLabel;
 
    protected void Page_Load(object sender, EventArgs e)
    
        Hashtable buildings = new Hashtable(), categories = new Hashtable(), departments = new Hashtable();
 
        StockHashTable(ref buildings, "SELECT * FROM sf_list_items_building a INNER JOIN sf_taxa b ON a.val=b.id");
        StockHashTable(ref categories, "SELECT * FROM sf_list_items_categories a INNER JOIN sf_taxa b ON a.val=b.id");
        StockHashTable(ref departments, "SELECT * FROM sf_list_items_department a INNER JOIN sf_taxa b ON a.val=b.id");
 
        DataTable myDataTable = new DataTable();
        DataColumn[] cols = new DataColumn[8];
        cols[0] = new DataColumn("Name");
        cols[1] = new DataColumn("Jobtitle");
        cols[2] = new DataColumn("Email");
        cols[3] = new DataColumn("Phone");
        cols[4] = new DataColumn("Categories");
        cols[5] = new DataColumn("Department");
        cols[6] = new DataColumn("Building");
        cols[7] = new DataColumn("Room");
 
        myDataTable.Columns.Add(cols[0]);
        myDataTable.Columns.Add(cols[1]);
        myDataTable.Columns.Add(cols[2]);
        myDataTable.Columns.Add(cols[3]);
        myDataTable.Columns.Add(cols[4]);
        myDataTable.Columns.Add(cols[5]);
        myDataTable.Columns.Add(cols[6]);
        myDataTable.Columns.Add(cols[7]);
 
        string ConnString = @"Data Source=(local)\SQLEXPRESS;UID=choose;Password=guTrut56";
        SqlConnection conn = new SqlConnection(ConnString);
        conn.Open();
 
        string sqlWheres = "";
        string sqlJoins = "";
 
        if (CategoryList != null && CategoryList != "")
        
            sqlWheres += " AND sflic.val = '" + CategoryList + "'";
            sqlJoins += " INNER JOIN sf_list_items_categories sflic ON a.content_id=sflic.content_id ";
        
        if (DepartmentList != null && DepartmentList != "")
        
            sqlWheres += " AND sflid.val = '" + DepartmentList + "'";
            sqlJoins += " INNER JOIN sf_list_items_department sflid ON a.content_id=sflid.content_id ";
        
 
        if (PhonePrefix == "" || PhonePrefix == null)
        
            PrefixLabel = "";
        
        else
        
            PrefixLabel = PhonePrefix;
        
 
 
        if (DirectoryName != null && DirectoryName != "")
        
            sqlWheres += " AND (a.title_ LIKE '%" + DirectoryName + "%')";
        
 
        if ((DirectoryName != null && DirectoryName != "") || (CategoryList != null && CategoryList != "") || (DepartmentList != null && DepartmentList != ""))
        
            string sqlQuery = "SELECT * FROM sf_list_items a INNER JOIN sf_lists b ON a.parent_id=b.content_id " + sqlJoins + " WHERE b.url_name_='directory' AND a.visible='1' " + sqlWheres + " ORDER BY a.last_name, a.first_name";
 
            SqlCommand cmd = new SqlCommand(sqlQuery, conn);
            SqlDataReader rdr = cmd.ExecuteReader();
            while (rdr.Read())
            
                myDataTable.LoadDataRow(new object[] rdr["title_"], rdr["job_title"], rdr["email"], rdr["phone"], categories[rdr["content_id"].ToString()], departments[rdr["content_id"].ToString()], buildings[rdr["content_id"].ToString()], rdr["room"] , true);
            
            rdr.Close();
 
            conn.Close();
 
            RadListView1.DataSource = myDataTable;
        
    
  public void StockHashTable(ref Hashtable ht, string qryString)
    
        string ConnString = @"Data Source=(local)\SQLEXPRESS;UID=choose;Password=guTrut56";
        SqlConnection conn = new SqlConnection(ConnString);
        conn.Open();
        SqlCommand cmd = new SqlCommand(qryString, conn);
        SqlDataReader rdr = cmd.ExecuteReader();
        while (rdr.Read())
        
            if (ht[rdr["content_id"].ToString()] != null)
                ht[rdr["content_id"].ToString()] += ", " + rdr["title_"].ToString();
            else
                ht[rdr["content_id"].ToString()] = rdr["title_"].ToString();
        
        rdr.Close();
        conn.Close();
    

The control works great except for one problem; I have three different fields the user can change in the edit screen for this control; CategoryList, DepartmentList, and DirectoryName.  The CategoryList and DepartmentList values are the GUID values for the appropriate simple classifications list.  Ideally I would like the user to select a category and/or department the same way a user can narrow the selection of the news or events widget by selecting a category or tag.

The DirectoryName field contain the full name of the employee.  I'd like some kind of drop down menu on the edit screen the user can use to select a specific employee.

How can I customize the edit screen on the backend?

Posted by Community Admin on 19-Dec-2011 00:00

Hello Kevin,

I think it would be best if you send us your whole project - the database and project files. I see you have custom taxonomies and some other customizations. Selecting directly from the database tables is not recommended. You should use the methods of TaxonomyManager to retrieve the needed taxonomies.

Best wishes,
Lubomir Velkov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 19-Dec-2011 00:00

Lubomir,
In what format do you want the database?  I could send it to you as an SQL file.  As well, it seems you'd need the tables sf_lists, sf_list_items, sf_list_items_categories, sf_list_items_departments, sf_list_items_buildings, and sf_taxa... How is the best way for me to generate this for you?

As for project files, you have all the relevant files already.

Posted by Community Admin on 19-Dec-2011 00:00

Hello Kevin,

You can create a backup of your SQL database and an archive of the configuration files in your ~/App_Data/Sitefinity/Configuration folder. Then you can upload them to a free file sharing service like www.megaupload.com and give me the link.

Best wishes,
Lubomir Velkov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed