Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Set DateTimeField webcontrol with date

$
0
0

We have several lists in a site collection. I am trying to populate some fields of one sharepoint list by opening its new form. There is one field which is a datetimefield and I am populating it on selectedindexchanged of a drop down. First time, it populates fine. But, if user selects another dropdownvalue this date do not get clear, neither it gets populate with different value. Please can someone tell me what should be the way to do it.

Here is my OnLoad code:

System.Web.UI.WebControls.TextBox startDatetb = null;

startDatetb = (TextBox)this.FindControl("ctl00$ctl40$g_e8454297_4ebf_43d4_b477_e728b5094b63$ff51$ctl00$ctl00$DateTimeField$DateTimeFieldDate");

startDatetb.ReadOnly = true;

Below code is on selectedindexchanged:

SPSite site = new SPSite(SPContext.Current.Site.Url);
SPWeb web = site.OpenWeb();

startDatetb.Text = "";
SPListItemCollection courseTakenCollection = Utilities.GetCourseStartDateByCourseTaken(web, Courseddl.SelectedValue, Studentsddl.SelectedValue);

                    if (courseTakenCollection.Count > 0)
                    {
                        foreach (SPListItem spi in courseTakenCollection)
                        {
                            startDatetb .Text = Convert.ToDateTime(spi["Course_x0020_Start_x0020_Date"]).ToShortDateString();
                        }
                    }

Thanks,

Nilesh


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>