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

RadDatePicker inside RadGrid

9 Answers 532 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
laila
Top achievements
Rank 1
laila asked on 01 Sep 2008, 10:56 AM
hi,

I have added to Template columns to RadGrid and placed Raddatepicker  control.

I have assigned some values to both the RadDatePickers when the Grid is Bound.

My problem is when i select the value it is showing the old value its not showing the new value what i selected. Can anybody give me the solution for this problem,.

i am giving sample code here'
 RadDatePicker radDtPckAss = (RadDatePicker)RadTaskDetails.Items[row].Cells[9].FindControl("RadDatePck_AssgnDt");
                           radDtPckAss.SelectedDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                           RadDatePicker radDtPck = (RadDatePicker)RadTaskDetails.Items[row].Cells[10].FindControl("RadDatePck_DelDt");
                           radDtPck.SelectedDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
i have assigned some values in gridbind for both the Datepickers..

 protected void RadTaskDetails_ItemCommand(object source, GridCommandEventArgs e)
    {
AddTaskAssign(Convert.ToInt32(fint_AssgnID), Convert.ToInt32(fstr_TaskID), Convert.ToInt32(fstr_ProjID), Convert.ToInt32(fstr_Team), Convert.ToInt32(fstr_Team), Convert.ToInt32(fstr_AssgnBy),(DateTime)radDtPckAss.SelectedDate ,(DateTime)radDtPck.SelectedDate, fstr_Comments);
}
//
radDtPckAss.SelectedDate ,(DateTime)radDtPck.SelectedDate both tthis datepickers are not showing the selected value..instead they are showing the old value what i have assigned..
please give me some sol,,

Please send u r reply to lcutish@gmail.com

9 Answers, 1 is accepted

Sort by
0
Missing User
answered on 01 Sep 2008, 11:18 AM
Hi laila,


Binding a RadDatePicker, RadTimePicker, or RadDateTimePicker control to a data source is easy provided you use the DbSelectedDate property. You can review the following online demo:

http://demos.telerik.com/aspnet/prometheus/Calendar/Examples/DatePicker/DataBinding/DefaultCS.aspx

Greetings,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
laila
Top achievements
Rank 1
answered on 01 Sep 2008, 11:33 AM
Hi,


  I have to select the date from the DatePicker control. Is it not possible to bind the datepickers with Datatable columns....as am not binding any cols to my Grid ..i just want to select the value in RadDatePicker(inside a RadGrid) and save to DataBase column..

Regards,
Laila
0
Missing User
answered on 01 Sep 2008, 12:57 PM
Hi laila,

Please find attached a sample web application that demonstrates the needed approach.

Regards,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
laila
Top achievements
Rank 1
answered on 02 Sep 2008, 07:19 AM
Hi Plamen ,

  Thanks for your early reply.
 
   I tried by going thru your sample project it didn't solve my problem.
I am having many fields, i want to select only assgndt, delvDt and comments field. If i go to use edit mode all fiellds will be editable.

Below i have sent the code snippet i m using of both aspx page and cs page by using ur methods...only change i did is instead of edit command i m using itemcommand and one link button.

Please suggest me some soln to get the recent value is DatePicker. It is still showing old value.

//CS code

 protected void RadTaskDetails_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
        string fint_AssgnID = "";
        string fstr_TaskID;
        string fstr_ProjID;
        string fstr_Team;
        string fstr_Assgnee;
        string fstr_AssgnBy;
        //string fstr_AssgnDt;
        //DateTime  fstr_DelDt;
        string fstr_Comments;

        if (e.CommandName == "btnAssgn")
        {
            fdtbl_GetTaskAssignID = miobj_TaskAssgn.GetMaxTaskAssignID();

            if (fdtbl_GetTaskAssignID.Rows.Count >= 1)
            {
                fint_AssgnID = fdtbl_GetTaskAssignID.Rows[0][0].ToString();
            }
            // TextBox ftxt = (CheckBox)RadGrTaskMaster.Items[fint_count].Cells[2].FindControl("chkSelect");

            fstr_TaskID = e.Item.Cells[2].Text;
            fstr_ProjID = e.Item.Cells[4].Text;
            DropDownList ddl = (DropDownList)e.Item.Cells[8].FindControl("ddlAsgnee");
            fstr_Assgnee = ddl.SelectedItem.Value;
            fstr_Team = ddl.SelectedItem.Value;
            fstr_AssgnBy = e.Item.Cells[6].Text;
              Telerik.Web.UI.RadDatePicker radDtPckAss =
               (Telerik.Web.UI.RadDatePicker)e.Item.Cells[9].FindControl("RadDatePck_AssgnDt");
            //Response.Write(radDatePicker.SelectedDate.ToString());
            Telerik.Web.UI.RadDatePicker radDtPckDvDt =
             (Telerik.Web.UI.RadDatePicker)e.Item.Cells[10].FindControl("RadDatePck_DelDt");
            TextBox txtCommnts = (TextBox)e.Item.Cells[11].FindControl("txtComments");
            fstr_Comments = txtCommnts.Text;
           
        AddTaskAssign(Convert.ToInt32(fint_AssgnID), Convert.ToInt32(fstr_TaskID), Convert.ToInt32(fstr_ProjID), Convert.ToInt32(fstr_Team), Convert.ToInt32(fstr_Team), Convert.ToInt32(fstr_AssgnBy), radDtPckAss.SelectedDate.Value, radDtPckDvDt.SelectedDate.Value, fstr_Comments);
}

//aspx code
<telerik:RadGrid ID="RadTaskDetails" runat="server" AutoGenerateColumns="false"  AllowPaging="True" OnUpdateCommand="RadTaskDetails_UpdateCommand"   >
       <MasterTableView>
            <Columns>
             <telerik:GridBoundColumn DataField="TASKID" HeaderText="TASKID" UniqueName="TASKID"></telerik:GridBoundColumn>
             <telerik:GridBoundColumn DataField="TASKNAME" HeaderText="TASKNAME" UniqueName="TASKNAME"></telerik:GridBoundColumn>
             <telerik:GridBoundColumn DataField="PROJID" UniqueName="PROJID" Visible="False" />
             <telerik:GridBoundColumn DataField="PROJECT" HeaderText="PROJECT" UniqueName="PROJECT"></telerik:GridBoundColumn>
             <telerik:GridBoundColumn DataField="PMID" HeaderText="PMID" UniqueName="PMID" Visible="False"></telerik:GridBoundColumn>
             <telerik:GridBoundColumn DataField="PROJECTMANAGER" HeaderText="PROJECTMANAGER" UniqueName="PROJECTMANAGER"></telerik:GridBoundColumn>
             <telerik:GridTemplateColumn HeaderText="ASSIGNEE" UniqueName="TemplateColumn1">
             <ItemTemplate>
             <asp:DropDownList ID="ddlAsgnee" runat="server">
             </asp:DropDownList>
             </ItemTemplate>
             </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderText="Assigned Date" UniqueName="Assigned Date">
              <ItemTemplate>
              <telerik:RadDatePicker ID="RadDatePck_AssgnDt" runat="server"  FocusedDate ="1/1/2005" MaxDate="12/31/2099" MinDate="1/1/1980"  >
                 </telerik:RadDatePicker>
              </ItemTemplate>
              <EditItemTemplate>
            <%--<asp:TextBox ID="txtAssgnDate" runat="server"></asp:TextBox>--%>
                <telerik:RadDatePicker ID="RadDatePck_AssgnDt" runat="server"  FocusedDate ="1/1/2005" MaxDate="12/31/2099" MinDate="1/1/1980"  >
                 </telerik:RadDatePicker>
               </EditItemTemplate>
             </telerik:GridTemplateColumn>
             <telerik:GridTemplateColumn HeaderText="Delivary Date" UniqueName="Delivary Date">
             <ItemTemplate>
              <telerik:RadDatePicker ID="RadDatePck_DelDt" runat="server"  FocusedDate ="1/1/2005" MaxDate="12/31/2099" MinDate="1/1/1980"  >
                 </telerik:RadDatePicker>
             </ItemTemplate>
             <EditItemTemplate>
            <%--<asp:TextBox ID="txtDelivaryDate" runat="server" AutoPostBack="false" ></asp:TextBox>--%>
                 <%--<asp:Calendar ID="calDelDate" runat="server"></asp:Calendar>--%>
                <telerik:RadDatePicker ID="RadDatePck_DelDt" runat="server"  FocusedDate ="1/1/2005" MaxDate="12/31/2099" MinDate="1/1/1980"  >
                 </telerik:RadDatePicker>
                 </EditItemTemplate>
             </telerik:GridTemplateColumn>
             <telerik:GridTemplateColumn HeaderText="Comments" UniqueName="Comments">
             <ItemTemplate>
             <asp:TextBox ID="txtComments" runat="server"  Text ="IMP" AutoPostBack="false" ></asp:TextBox>
             </ItemTemplate>
             <EditItemTemplate>
            <asp:TextBox ID="txtComments" runat="server"  Text ="IMP" AutoPostBack="false" ></asp:TextBox>
             </EditItemTemplate>
             </telerik:GridTemplateColumn>
              <telerik:GridTemplateColumn UniqueName="TemplateColumn"  HeaderText="ASSIGN">
                      <ItemTemplate >
                      <asp:LinkButton runat="server" ID="btnAssgn" Text="Assgn"   CommandName="btnAssgn" CausesValidation="false"  ForeColor="Blue"  ></asp:LinkButton>
                      </ItemTemplate>
                      </telerik:GridTemplateColumn>
               <%-- <telerik:GridEditCommandColumn>
                 </telerik:GridEditCommandColumn>--%>
            </Columns>
             <ExpandCollapseColumn Visible="False">
                    <HeaderStyle Width="19px" />
                </ExpandCollapseColumn>
                <RowIndicatorColumn Visible="False">
                    <HeaderStyle Width="20px" />
                </RowIndicatorColumn>
       </MasterTableView>
       </telerik:RadGrid>

0
Missing User
answered on 03 Sep 2008, 03:02 PM
Hello laila,

The following code example demonstrates how to achieve your goal:

.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 
 
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
<head runat="server"
    <title>Untitled Page</title> 
</head> 
<body> 
    <form id="form1" runat="server"
        <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
        <div> 
            <telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource" OnItemCommand="RadGrid1_ItemCommand"
                <MasterTableView AutoGenerateColumns="false"
                    <Columns> 
                        <telerik:GridTemplateColumn UniqueName="MyGridTemplateColumn" HeaderText="MyGridTemplateColumn"
                            <ItemTemplate> 
                                <telerik:RadDatePicker ID="RadDatePicker1" runat="server"
                                </telerik:RadDatePicker> 
                            </ItemTemplate> 
                        </telerik:GridTemplateColumn> 
                    <telerik:GridTemplateColumn UniqueName="TemplateColumn"  HeaderText="ASSIGN"
                      <ItemTemplate > 
                        <asp:LinkButton runat="server" ID="btnAssgn" Text="Assgn"   CommandName="btnAssgn" CausesValidation="false"  ForeColor="Blue"  ></asp:LinkButton> 
                      </ItemTemplate> 
                      </telerik:GridTemplateColumn>                         
                    </Columns> 
                </MasterTableView> 
            </telerik:RadGrid>         
        </div> 
    </form> 
</body> 
</html> 
 


.cs
using System; 
using System.Data; 
using System.Configuration; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Web.UI.HtmlControls; 
using System.Collections; 
 
using Telerik.Web.UI; 
 
public partial class _Default : System.Web.UI.Page  
    protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) 
    { 
        RadGrid1.DataSource = new String[] { "aaa""bbb" }; 
    } 
    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.CommandName == "btnAssgn"
        { 
            GridDataItem gridDataItem = (GridDataItem)e.Item; 
            RadDatePicker radDatePicker = 
                (RadDatePicker)gridDataItem["MyGridTemplateColumn"].FindControl("RadDatePicker1"); 
 
            Response.Write(radDatePicker.SelectedDate.ToString()); 
        } 
    } 

Hope this helps






Sincerely yours,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
laila
Top achievements
Rank 1
answered on 04 Sep 2008, 05:28 AM
Hi,

   Thanks for your reply.

    I  changed my code according to your sample code.
  
But for me in ItemCommand its showing SelectedDate as old Date.

My requirement is when user selects a date say 31Aug 2008 it should show me that date , not the current date when i click the Assign(Link button). Please give me some suggetions. Please tell me what can be the reason for this.

Thanks in adance.


Regards,
Laila
0
Missing User
answered on 04 Sep 2008, 07:36 AM
Hello laila,


I tried to reproduce the problem locally, but to no avail. Can you please check the attached project and the movie and let me know if I am missing something?

Kind regards,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
laila
Top achievements
Rank 1
answered on 04 Sep 2008, 10:20 AM
Hi,
  What you have done is right. But after u click assign button inside the ItemCommand i m not able to get the lastest date. Its showing old date .....

Give me some suggestion

Regards,
Laila
0
Missing User
answered on 04 Sep 2008, 10:35 AM
Hello laila,



Please, verify that RadGrid is properly populated with data. You can find more information here:

http://www.telerik.com/help/aspnet-ajax/grdadvanceddatabinding.html
http://demos.telerik.com/aspnet/prometheus/Grid/Examples/Programming/NeedDataSource/DefaultCS.aspx






Kind regards,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Calendar
Asked by
laila
Top achievements
Rank 1
Answers by
Missing User
laila
Top achievements
Rank 1
Share this question
or