This is a migrated thread and some comments may be shown as answers.

RadDatePicker and RadEditor Binding in a DetailsView

2 Answers 133 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Drammy
Top achievements
Rank 1
Drammy asked on 24 Jun 2008, 08:15 PM
Hi all,

I have grid that on insert / edit opens a RadWindow using functionality I have found on this website.  This default functionality uses a default view to present the edit form and I have amended it slightly changing two of the text boxes to a RadDatePicker and a RadEditor.  These additional RadControls bind properly but the binding appears to only be one way.  Upon update/insert any data in these RadControls is ignored and only the data from the text boxes goes into the database.

Can anyopne help me out please?  I have attached the code below:

PersonEditForm.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PersonEditForm.aspx.cs" Inherits="HonoursBoard.Admin.PersonEditForm" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml" > 
    <head id="Head1" runat="server">  
        <title>Untitled Page</title> 
    </head> 
    <body> 
        <form id="form1" runat="server">  
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server">  
            </telerik:RadScriptManager> 
            <div> 
                <script type="text/javascript">  
                function CloseAndRebind(args)  
                {  
                    GetRadWindow().Close();  
                    GetRadWindow().BrowserWindow.refreshGrid(args);  
                }  
                       
                function GetRadWindow()  
                {  
                    var oWindow = null;  
 
                    if (window.radWindow)  
                        oWindow = window.radWindow; //Will work in Moz in all cases, including classic dialog  
                    else if (window.frameElement.radWindow)  
                        oWindow = window.frameElement.radWindow;//IE (and Moz as well)  
                        return oWindow;  
                 }  
                 function CancelEdit()  
                 {  
                    GetRadWindow().Close();    
                 }  
                </script> 
                <asp:DetailsView ID="DetailsView1" DataKeyNames="intPersonID" runat="server" AutoGenerateRows="False" 
                    DataSourceID="SqlDataSource1" Height="50px" Width="125px" OnItemCommand="DetailsView1_ItemCommand">  
                    <Fields> 
                        <asp:BoundField DataField="strTitle" HeaderText="Title" SortExpression="strTitle" /> 
                        <asp:BoundField DataField="strFirstName" HeaderText="First Name" SortExpression="strFirstName" /> 
                        <asp:BoundField DataField="strInitials" HeaderText="Initials" SortExpression="strInitials" /> 
                        <asp:BoundField DataField="strLastName" HeaderText="Last Name" SortExpression="strLastName" /> 
                        <asp:TemplateField HeaderText="Date Of Birth">  
                            <ItemTemplate> 
                                <telerik:RadDatePicker EnableViewState="false" MinDate="01/01/1850" 
                                    MaxDate="01/01/2100" Skin="Telerik" ID="RadDatePicker1" 
                                    DbSelectedDate='<%# DataBinder.Eval(Container.DataItem, "datDateOfBirth") %>' 
                                    Runat="server"></telerik:RadDatePicker> 
                            </ItemTemplate> 
                        </asp:TemplateField> 
                        <asp:TemplateField HeaderText="Biography">  
                            <ItemTemplate> 
                                <telerik:RadEditor EnableViewState="false" ID="RadEditor1" runat="server" Skin="Telerik" 
                                    ToolsFile="~/Editor/BasicTools.xml" Width="400px" Height="200px" 
                                    Content='<%# DataBinder.Eval(Container.DataItem, "strBiography") %>'>  
                                </telerik:RadEditor> 
                            </ItemTemplate> 
                        </asp:TemplateField> 
                        <asp:CommandField ShowEditButton="True" /> 
                        <asp:CommandField ShowInsertButton="True" InsertText="Add" /> 
                    </Fields> 
                </asp:DetailsView> 
            </div> 
            <asp:SqlDataSource ID="SqlDataSource1" runat="server"   
                ConnectionString="<%$ ConnectionStrings:dbGolfHonoursConnectionString %>"   
                InsertCommand="InsertAPerson" InsertCommandType="StoredProcedure"   
                SelectCommand="SelectPersonByPersonID" SelectCommandType="StoredProcedure"   
                UpdateCommand="UpdateAPerson" UpdateCommandType="StoredProcedure">  
                <SelectParameters> 
                    <asp:QueryStringParameter DefaultValue="0" Name="PersonID"   
                        QueryStringField="intPersonID" Type="Int32" /> 
                </SelectParameters> 
                <UpdateParameters> 
                    <asp:Parameter Name="intPersonID" Type="Int32" /> 
                    <asp:Parameter Name="strTitle" Type="String" /> 
                    <asp:Parameter Name="strFirstName" Type="String" /> 
                    <asp:Parameter Name="strInitials" Type="String" /> 
                    <asp:Parameter Name="strLastName" Type="String" /> 
                    <asp:Parameter Name="strBiography" Type="String" /> 
                    <asp:Parameter Name="datDateOfBirth" Type="DateTime" /> 
                </UpdateParameters> 
                <InsertParameters> 
                    <asp:Parameter Name="strTitle" Type="String" /> 
                    <asp:Parameter Name="strFirstName" Type="String" /> 
                    <asp:Parameter Name="strInitials" Type="String" /> 
                    <asp:Parameter Name="strLastName" Type="String" /> 
                    <asp:Parameter Name="strBiography" Type="String" /> 
                    <asp:Parameter Name="datDateOfBirth" Type="DateTime" /> 
                </InsertParameters> 
            </asp:SqlDataSource> 
        </form> 
    </body> 
</html> 


PersonEditForm.aspx.cs
using System;  
using System.Collections;  
using System.Configuration;  
using System.Data;  
using System.Linq;  
using Telerik.Web.UI;  
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;  
 
namespace HonoursBoard.Admin  
{  
    public partial class PersonEditForm : System.Web.UI.Page  
    {  
        protected void Page_Init(object sender, EventArgs e)  
        {  
            if (Request.QueryString["intPersonID"] == null)  
            {  
                DetailsView1.DefaultMode = DetailsViewMode.Insert;  
            }  
            else 
            {  
                DetailsView1.DefaultMode = DetailsViewMode.Edit;  
            }  
        }  
 
        protected void DetailsView1_ItemCommand(object sender, System.Web.UI.WebControls.DetailsViewCommandEventArgs e)  
        {  
            if (e.CommandName == "Update")  
            {  
                ClientScript.RegisterStartupScript(Page.GetType(), "mykey""CloseAndRebind();"true);  
            }  
            else if (e.CommandName == "Insert")  
            {  
                ClientScript.RegisterStartupScript(Page.GetType(), "mykey""CloseAndRebind('navigateToInserted');"true);  
            }  
            else 
            {  
                ClientScript.RegisterStartupScript(Page.GetType(), "mykey""CancelEdit();"true);  
            }  
        }  
    }  

Thanks in advance for any help offered,

Martyn

2 Answers, 1 is accepted

Sort by
0
Drammy
Top achievements
Rank 1
answered on 24 Jun 2008, 10:21 PM
Please ignore my stupidity!

Problem solved - I guess I need to grab me some sleep!

I had it in my head I was using Bind() rather than an outdated Eval function...


Sorry to waste anyone's time reading this thread.
0
Hoon
Top achievements
Rank 1
answered on 08 Jul 2011, 10:54 PM
Your foolishness saves a lot of Genius.
Tags
Calendar
Asked by
Drammy
Top achievements
Rank 1
Answers by
Drammy
Top achievements
Rank 1
Hoon
Top achievements
Rank 1
Share this question
or