c# use Calendar.SelectedDate in a repeater control, but month is giving me “00”










0















I am trying to make a webform using asp.net.
When a linked button is clicked (within a repeater), a calendar is supposed to popup. The date selected on the calendar is supposed to fill out the text box "start date".



This is one item inside Repeater1:



<td>
<asp:TextBox runat="server" ID="txtStart" Text='<%# DataBinder.Eval(Container.DataItem,"StartDate") %>' />
<asp:LinkButton ID="btnCalendar" runat="server"
CssClass="btn btn-xs"OnClick="ShowCalendar">
<span aria-hidden="true" class="glyphicon glyphicon-calendar"></span>
</asp:LinkButton>
</td>


After all other items, here is the Calendar:



 <asp:Calendar ID="Calendar1" runat="server" Visibile="false" SelectionMode="Day" onselectionchanged="Calendar1_SelectionChanged">
</asp:Calendar>


Code behind:



protected void Calendar1_SelectionChanged(object sender, EventArgs e){
if (Repeater1.Items.Count == 1)

TextBox txtStart = (TextBox)Repeater1.Items[0].FindControl("txtStart");
DateTimeFormatInfo usDtfi = new CultureInfo("en-US", false).DateTimeFormat;

txtStart.Text = Calendar1.SelectedDate.ToString("yyyymmdd");



This code behind is just adding text to the fist item of the repeater



My problem is:



The SelectedDate of Calendar is giving me the correct year and date, but is giving me value "00" for the month



This is the link to a screenshot of the part of my webform which is problematic



Thank you!










share|improve this question






















  • The dateformat string is imperfect, mm is minutes, MM is months, you want: Calendar1.SelectedDate.ToString("yyyyMMdd");

    – Davesoft
    Nov 14 '18 at 19:17












  • @Davesoft Thank you so much

    – Greta Liu
    Nov 14 '18 at 19:24















0















I am trying to make a webform using asp.net.
When a linked button is clicked (within a repeater), a calendar is supposed to popup. The date selected on the calendar is supposed to fill out the text box "start date".



This is one item inside Repeater1:



<td>
<asp:TextBox runat="server" ID="txtStart" Text='<%# DataBinder.Eval(Container.DataItem,"StartDate") %>' />
<asp:LinkButton ID="btnCalendar" runat="server"
CssClass="btn btn-xs"OnClick="ShowCalendar">
<span aria-hidden="true" class="glyphicon glyphicon-calendar"></span>
</asp:LinkButton>
</td>


After all other items, here is the Calendar:



 <asp:Calendar ID="Calendar1" runat="server" Visibile="false" SelectionMode="Day" onselectionchanged="Calendar1_SelectionChanged">
</asp:Calendar>


Code behind:



protected void Calendar1_SelectionChanged(object sender, EventArgs e){
if (Repeater1.Items.Count == 1)

TextBox txtStart = (TextBox)Repeater1.Items[0].FindControl("txtStart");
DateTimeFormatInfo usDtfi = new CultureInfo("en-US", false).DateTimeFormat;

txtStart.Text = Calendar1.SelectedDate.ToString("yyyymmdd");



This code behind is just adding text to the fist item of the repeater



My problem is:



The SelectedDate of Calendar is giving me the correct year and date, but is giving me value "00" for the month



This is the link to a screenshot of the part of my webform which is problematic



Thank you!










share|improve this question






















  • The dateformat string is imperfect, mm is minutes, MM is months, you want: Calendar1.SelectedDate.ToString("yyyyMMdd");

    – Davesoft
    Nov 14 '18 at 19:17












  • @Davesoft Thank you so much

    – Greta Liu
    Nov 14 '18 at 19:24













0












0








0








I am trying to make a webform using asp.net.
When a linked button is clicked (within a repeater), a calendar is supposed to popup. The date selected on the calendar is supposed to fill out the text box "start date".



This is one item inside Repeater1:



<td>
<asp:TextBox runat="server" ID="txtStart" Text='<%# DataBinder.Eval(Container.DataItem,"StartDate") %>' />
<asp:LinkButton ID="btnCalendar" runat="server"
CssClass="btn btn-xs"OnClick="ShowCalendar">
<span aria-hidden="true" class="glyphicon glyphicon-calendar"></span>
</asp:LinkButton>
</td>


After all other items, here is the Calendar:



 <asp:Calendar ID="Calendar1" runat="server" Visibile="false" SelectionMode="Day" onselectionchanged="Calendar1_SelectionChanged">
</asp:Calendar>


Code behind:



protected void Calendar1_SelectionChanged(object sender, EventArgs e){
if (Repeater1.Items.Count == 1)

TextBox txtStart = (TextBox)Repeater1.Items[0].FindControl("txtStart");
DateTimeFormatInfo usDtfi = new CultureInfo("en-US", false).DateTimeFormat;

txtStart.Text = Calendar1.SelectedDate.ToString("yyyymmdd");



This code behind is just adding text to the fist item of the repeater



My problem is:



The SelectedDate of Calendar is giving me the correct year and date, but is giving me value "00" for the month



This is the link to a screenshot of the part of my webform which is problematic



Thank you!










share|improve this question














I am trying to make a webform using asp.net.
When a linked button is clicked (within a repeater), a calendar is supposed to popup. The date selected on the calendar is supposed to fill out the text box "start date".



This is one item inside Repeater1:



<td>
<asp:TextBox runat="server" ID="txtStart" Text='<%# DataBinder.Eval(Container.DataItem,"StartDate") %>' />
<asp:LinkButton ID="btnCalendar" runat="server"
CssClass="btn btn-xs"OnClick="ShowCalendar">
<span aria-hidden="true" class="glyphicon glyphicon-calendar"></span>
</asp:LinkButton>
</td>


After all other items, here is the Calendar:



 <asp:Calendar ID="Calendar1" runat="server" Visibile="false" SelectionMode="Day" onselectionchanged="Calendar1_SelectionChanged">
</asp:Calendar>


Code behind:



protected void Calendar1_SelectionChanged(object sender, EventArgs e){
if (Repeater1.Items.Count == 1)

TextBox txtStart = (TextBox)Repeater1.Items[0].FindControl("txtStart");
DateTimeFormatInfo usDtfi = new CultureInfo("en-US", false).DateTimeFormat;

txtStart.Text = Calendar1.SelectedDate.ToString("yyyymmdd");



This code behind is just adding text to the fist item of the repeater



My problem is:



The SelectedDate of Calendar is giving me the correct year and date, but is giving me value "00" for the month



This is the link to a screenshot of the part of my webform which is problematic



Thank you!







c# asp.net repeater






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 19:13









Greta LiuGreta Liu

52




52












  • The dateformat string is imperfect, mm is minutes, MM is months, you want: Calendar1.SelectedDate.ToString("yyyyMMdd");

    – Davesoft
    Nov 14 '18 at 19:17












  • @Davesoft Thank you so much

    – Greta Liu
    Nov 14 '18 at 19:24

















  • The dateformat string is imperfect, mm is minutes, MM is months, you want: Calendar1.SelectedDate.ToString("yyyyMMdd");

    – Davesoft
    Nov 14 '18 at 19:17












  • @Davesoft Thank you so much

    – Greta Liu
    Nov 14 '18 at 19:24
















The dateformat string is imperfect, mm is minutes, MM is months, you want: Calendar1.SelectedDate.ToString("yyyyMMdd");

– Davesoft
Nov 14 '18 at 19:17






The dateformat string is imperfect, mm is minutes, MM is months, you want: Calendar1.SelectedDate.ToString("yyyyMMdd");

– Davesoft
Nov 14 '18 at 19:17














@Davesoft Thank you so much

– Greta Liu
Nov 14 '18 at 19:24





@Davesoft Thank you so much

– Greta Liu
Nov 14 '18 at 19:24












1 Answer
1






active

oldest

votes


















0














Just change the line



 txtStart.Text = Calendar1.SelectedDate.ToString("yyyymmdd");


with



 txtStart.Text = Calendar1.SelectedDate.ToString("yyyyMMdd");





share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53307258%2fc-sharp-use-calendar-selecteddate-in-a-repeater-control-but-month-is-giving-me%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Just change the line



     txtStart.Text = Calendar1.SelectedDate.ToString("yyyymmdd");


    with



     txtStart.Text = Calendar1.SelectedDate.ToString("yyyyMMdd");





    share|improve this answer



























      0














      Just change the line



       txtStart.Text = Calendar1.SelectedDate.ToString("yyyymmdd");


      with



       txtStart.Text = Calendar1.SelectedDate.ToString("yyyyMMdd");





      share|improve this answer

























        0












        0








        0







        Just change the line



         txtStart.Text = Calendar1.SelectedDate.ToString("yyyymmdd");


        with



         txtStart.Text = Calendar1.SelectedDate.ToString("yyyyMMdd");





        share|improve this answer













        Just change the line



         txtStart.Text = Calendar1.SelectedDate.ToString("yyyymmdd");


        with



         txtStart.Text = Calendar1.SelectedDate.ToString("yyyyMMdd");






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 14 '18 at 22:07









        aliasscealiassce

        931414




        931414





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53307258%2fc-sharp-use-calendar-selecteddate-in-a-repeater-control-but-month-is-giving-me%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            Node.js Script on GitHub Pages or Amazon S3

            Museum of Modern and Contemporary Art of Trento and Rovereto