tags:

views:

48

answers:

1
 <label for="Date">
            dateformate:
            <span id="date-<%=Model.ID%>"><%=Html.EditorFor(model => model.Date)%></span>
        </label>

I need to assign datetimepicker for this lable? when any user clicks on the date label datetimepciker should popup? thanks

A: 

Check out the JQuery UI Datepicker.

Your case is a bit special since the ID is generated dynamically but it is still pretty easy:

$("span[id^='date-']").datepicker();

Taking a closer look, I just realized that you are trying to tie the datepicker to a span where it would normally be assigned to a textbox. So really what you are going to want is to add a textbox and then do this:

$("input[id^='date-']").datepicker();

Also make sure that you have the jQuery UI CSS referenced. Something like this on your page or site.master:

@import url(/Content/ui.all.css);
Bradley Mountford
Yes I did that.. but problem is after choosing date from datpicker when I am want to clear the date i am not able to clear the date its showing me previous date which I was selected..thanks
kumar
THanks for your response I updated like this.. $("span[id^='date-']").datepicker({ duration: '', showTime: true, constrainInput: true, stepMinutes: 15, stepHours: 1, altTimeField: '', time24h: false, minDate: 0 });
kumar
But still havig problem..I am not getting Datepicker pop up window?
kumar
Are you missing a reference to the CSS file for jQuery UI?
Bradley Mountford
Yes but I am geting two textboxes after removing span from there and I am not able to clear the textbox if i dont want date to be selected.that Is I am not able to make null textbox? <label for="Date"> DateForMate: <input id="exc-followup-<%=Model.ID%>" /><%=Html.EditorFor(model => model.Date)%> </label>
kumar
Are you saying that you want to clear the input after you have selected a date?
Bradley Mountford
yes Sir.. I need..
kumar
Well....the user could just clear the input manually, or you could create a clear button to do it.
Bradley Mountford
the user can not able to celar the input manually if he is its showing the same date which user selected previously..thanks
kumar