EditTemplate problem

4 posts, 0 answers
  1. Jeremy
    Jeremy avatar
    4 posts
    Member since:
    Jun 2010

    Posted 21 Jun 2010 Link to this post

    In my edit template, i am trying to bind the items to the Textbox for editing, this does not work and I am left with a blank textbox.  I am data binding on a datatable.  the item template shows the data correctly, I then have to hit the edit button twice(dunno why) then i see the 3 empty text boxes.  Any help is appreciated.

    //Code Behind file
     dt = new DataTable();
                dt.Columns.Add("SummaryID");
                dt.Columns.Add("BegTimeStamp");
                dt.Columns.Add("EndTimeStamp");
                DataRow dr = dt.NewRow();
                dr["SummaryID"] = "Rule 1";
                dr["BegTimeStamp"] = "5/21/2010 6:00:00 AM";
                dr["EndTimeStamp"] = "5/24/2010 6:00:00 PM";
                dt.Rows.Add(dr);

      protected void ruleLV_NeedDataSource(object sender, RadListViewNeedDataSourceEventArgs e)
        {
            ruleLV.DataSource = dt;
        }
    //end code behind

    <telerik:RadListView ID="ruleLV" runat="server"
                                ItemPlaceholderID="RulePlaceHolder"
                                onneeddatasource="ruleLV_NeedDataSource" Skin="Windows7"
                                 onselectedindexchanged="ruleLV_SelectedIndexChanged"
                                 onitemcommand="ruleLV_ItemCommand" DataKeyNames="SummaryID"
                                >
                             <LayoutTemplate>
                              <table runat="server" >
                               <tr>
                                <th id="SummaryIdHdr" runat="server" width="150px">Rule ID</th>
                                <th id="BegTimeStampHdr" runat="server" width="200px">Start Date/Time</th>
                                <th id="EndTimeStampHdr" runat="server" width="200px">End Date/Time</th>
                               </tr>
                               
                               <tr id="RulePlaceHolder" runat="server" ></tr>
                              
                              </table>
                               <fieldset style="text-align: center; background-color: white;">
                              
                            </fieldset>
                             </LayoutTemplate>
                                <EditItemTemplate>
                                 
                                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("SummaryID") %>'></asp:TextBox>
                                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("BegTimeStamp") %>'></asp:TextBox>
                                    <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("EndTimeStamp") %>'></asp:TextBox>
                                </EditItemTemplate>
                             <ItemTemplate>
                       
                             <tr ID="rules" bgColor="White" runat="server">
                                <td> <%#Eval("SummaryID") %></td>
                                <td> <%#Eval("BegTimeStamp") %></td>
                                <td> <%#Eval("EndTimeStamp") %></td>
                                <td><asp:Button Id="EditButton" Text="Edit" runat="server" CommandName="Edit" /> </td>
                              </tr >
                    
                             </ItemTemplate>
                          
                           
                            </telerik:RadListView>
  2. Rosen
    Admin
    Rosen avatar
    3237 posts

    Posted 22 Jun 2010 Link to this post

    Hi Jeremy,

    Can you please post page's full code-behind?

    All the best,
    Rosen
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jeremy
    Jeremy avatar
    4 posts
    Member since:
    Jun 2010

    Posted 22 Jun 2010 Link to this post

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.Data.SqlClient;
    using APSBusinessLayer;
    using Telerik.Web.UI;

    public partial class RCMTest : System.Web.UI.Page
    {
        DataTable dt;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                PopulateCampaignTree();

                this.Master.SetUserLabel = "Hello, " + Session["User"].ToString();
                dt = new DataTable();
                dt.Columns.Add("SummaryID");
                dt.Columns.Add("BegTimeStamp");
                dt.Columns.Add("EndTimeStamp");
                DataRow dr = dt.NewRow();
                dr["SummaryID"] = "Rule 1";
                dr["BegTimeStamp"] = "5/21/2010 6:00:00 AM";
                dr["EndTimeStamp"] = "5/24/2010 6:00:00 PM";
                dt.Rows.Add(dr);
                dr = dt.NewRow();
                dr["SummaryID"] = "Rule 2";
                dr["BegTimeStamp"] = "5/21/2010 6:00:00 AM";
                dr["EndTimeStamp"] = "5/24/2010 6:00:00 PM";
                dt.Rows.Add(dr);
     
                
            }
        
        }

        private void PopulateCampaignTree()
        {
            rcmTree.Nodes.Clear();
            DataTable propDT = new DataTable();
            SqlConnection sqlConn = GetSqlConn();
            try
            {
                sqlConn.Open();
                PropertyOptions.LoadPropertyOptions(sqlConn, ref propDT);
            }
            catch
            { }
            finally
            {
                sqlConn.Close();
            }

            List<RadTreeNode> siteList = new List<RadTreeNode>();
            RadTreeNode root = new RadTreeNode();
            foreach (DataRow dr in propDT.Rows)
            {
                RadTreeNode rcmNode = new RadTreeNode();
                rcmNode.Text = dr["PropertyID"].ToString();

                Dictionary<string, string> myCampaignDict1 = new Dictionary<string, string>(); ;
                Dictionary<string, string> myColorDict1 = new Dictionary<string, string>();
                try
                {

                    sqlConn.Open();
                    myCampaignDict1 = APSBusinessLayer.RCM.LoadCampaignNames(sqlConn, dr["PropertyID"].ToString());
                    myColorDict1 = APSBusinessLayer.RCM.GetCampaignStatus(sqlConn, dr["PropertyID"].ToString());
                }
                catch { }
                finally
                {
                    sqlConn.Close();
                }

                foreach (KeyValuePair<string, string> kvp in myCampaignDict1)
                {
                    RadTreeNode campNode = new RadTreeNode(idRb.Checked ? kvp.Key + " (" + kvp.Value + ")" : kvp.Value + " (" + kvp.Key + ")");
                    if (myColorDict1.ContainsKey(kvp.Key))
                    {
                       
                        switch (myColorDict1[kvp.Key])
                        {
                            case "red":
                                campNode.ForeColor = System.Drawing.Color.Red;
                                break;
                            case "gray":
                                campNode.ForeColor = System.Drawing.Color.Gray;
                                break;
                            case "green":
                                campNode.ForeColor = System.Drawing.Color.Green;
                                break;
                            case "blue":
                                campNode.ForeColor = System.Drawing.Color.Blue;
                                break;
                        }
                    }
                    rcmNode.Nodes.Add(campNode);
                }
               
                rcmTree.Nodes.Add(rcmNode);
            }
        
           
            
        }


        protected SqlConnection GetSqlConn()
        {
            return new SqlConnection(Session["ConString"].ToString());
        }

        protected void idRb_CheckedChanged(object sender, EventArgs e)
        {
            PopulateCampaignTree();
        }
        protected void nameRB_CheckedChanged(object sender, EventArgs e)
        {
            PopulateCampaignTree();
        }
        protected void addSegmentBtn_Click(object sender, EventArgs e)
        {
            RadTreeNode segmentNode = new RadTreeNode();
            segmentNode.Text = "Segment 1";
            progressiveTree.Nodes.Add(segmentNode);
            segmentNode.Value = segmentNode.GetFullPath("/");
           
        }

        protected void progressiveTree_ContextMenuItemClick(object sender, RadTreeViewContextMenuEventArgs e)
        {
            RadTreeNode clickedNode = e.Node;

            switch (e.MenuItem.Text)
            {
                case "Add Segment":
                    RadTreeNode newSegment = new RadTreeNode(string.Format("New Segment {0}",progressiveTree.Nodes.Count + 1));
                    progressiveTree.Nodes.Add(newSegment);
                    newSegment.Value = newSegment.GetFullPath("/");
                    startNodeInEditMode(newSegment.Value);
                    break;
                case "Add Multiplier":
                    if (clickedNode.ParentNode == null)
                    {
                        RadTreeNode newMultiplier = new RadTreeNode("2");
                        clickedNode.Nodes.Add(newMultiplier);
                        clickedNode.Expanded = true;
                        newMultiplier.Value = clickedNode.Value + newMultiplier.Text;
                        startNodeInEditMode(newMultiplier.Value);
                    }
                    else
                    {
                        RadTreeNode newMultiplier = new RadTreeNode("2");
                        clickedNode.ParentNode.Nodes.Add(newMultiplier);
                        newMultiplier.Value = clickedNode.ParentNode.Value + newMultiplier.Text;
                        clickedNode.ParentNode.Expanded = true;
                        startNodeInEditMode(newMultiplier.Value);
                    }
                    break;

                case "Edit Item":
                    startNodeInEditMode(clickedNode.Value);
                    break;
                case "Delete Item":
                    clickedNode.Remove();
                    break;
            }
        }

        private void startNodeInEditMode(string nodeValue)
        {
            //find the node by its Value and edit it when page loads
            string js = "Sys.Application.add_load(editNode); function editNode(){ ";
            js += "var tree = $find(\"" + progressiveTree.ClientID + "\");";
            js += "var node = tree.findNodeByValue('" + nodeValue + "');";
            js += "if (node) node.startEdit();";
            js += "Sys.Application.remove_load(editNode);};";

            RadScriptManager.RegisterStartupScript(Page, Page.GetType(), "nodeEdit", js, true);
        }

        protected void progressiveTree_NodeEdit(object sender, RadTreeNodeEditEventArgs e)
        {
            e.Node.Text = e.Text;
        }
        protected void ruleLV_NeedDataSource(object sender, RadListViewNeedDataSourceEventArgs e)
        {
            ruleLV.DataSource = dt;
        }
        protected void ruleLV_SelectedIndexChanged(object sender, EventArgs e)
        {
        }
        protected void ruleLV_ItemCommand(object sender, RadListViewCommandEventArgs e)
        {
           
        }
  5. Jeremy
    Jeremy avatar
    4 posts
    Member since:
    Jun 2010

    Posted 22 Jun 2010 Link to this post

    Error is in the code behind.  Datatable is being reset after each postback because it is created inside of the page.  Moving that out of the !Page.IsPostback condition fixed the problem.  Sorry I am not used to writing extensive web applications.  Thank you for your time.
Back to Top