[Solved] MKB TimePicker displays Current Time if value is 00:00 in ASP.Net

Last Reply one year ago By dharmendr

Posted one year ago

it will allow me to save 00:00 but throwing error while i am populating same value in grid view.

guied me to handle this value

<asp:TemplateField HeaderText="Departure" ItemStyle-HorizontalAlign="Center" ItemStyle-Wrap="true">
    <ItemTemplate>
        <cc1:TimeSelector ID="tmsDepartureTime" ClientIDMode="Predictable" Hour='<%# Eval("DepartureTime").ToString()==""?8:(Object)Convert.ToDateTime(Eval("DepartureTime")).Hour %>' Minute='<%#  Eval("DepartureTime").ToString()==""?0:(Object)Convert.ToDateTime(Eval("DepartureTime")).Minute %>' AmPm='<%#  Eval("DepartureTime").ToString()==""?TimeSelector.AmPmSpec.AM:(Convert.ToInt32(Convert.ToDateTime(Eval("DepartureTime")).Hour)<12)?TimeSelector.AmPmSpec.AM:TimeSelector.AmPmSpec.PM %>' MinuteIncrement="1" CssClass="TimePicker" runat="server" Font-Size="Larger" DisplaySeconds="false" SelectedTimeFormat="TwentyFour">
        </cc1:TimeSelector>
    </ItemTemplate>
</asp:TemplateField>

Now in mkb time picker if i set '00' as hour it is showing currun hour.

Posted one year ago

Hi suraj@123,

Check this example. Now please take its reference and correct your code.

HTML

<asp:GridView runat="server" ID="GridView1" AutoGenerateColumns="false">
    <Columns>
        <asp:BoundField DataField="Id" HeaderText="Id" />
        <asp:TemplateField HeaderText="Departure" ItemStyle-HorizontalAlign="Center" ItemStyle-Wrap="true">
            <ItemTemplate>
                <cc1:TimeSelector ID="tmsDepartureTime" ClientIDMode="Predictable" Hour='<%# Eval("DepartureTime").ToString()==""?8:Convert.ToDateTime(Eval("DepartureTime").ToString()).Hour %>'
                    Minute='<%#  Eval("DepartureTime").ToString()==""?0:Convert.ToDateTime(Eval("DepartureTime").ToString()).Minute %>'
                    AmPm='<%#  Eval("DepartureTime").ToString()==""?TimeSelector.AmPmSpec.AM:(Convert.ToInt32(Convert.ToDateTime(Eval("DepartureTime").ToString()).Hour)<12)?TimeSelector.AmPmSpec.AM:TimeSelector.AmPmSpec.PM %>'
                    MinuteIncrement="1" CssClass="TimePicker" runat="server" Font-Size="Larger" DisplaySeconds="false"
                    SelectedTimeFormat="Twelve">
                </cc1:TimeSelector>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

Code

C#

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        System.Data.DataTable dt = new System.Data.DataTable();
        dt.Columns.AddRange(new System.Data.DataColumn[2] { 
            new System.Data.DataColumn("Id", typeof(int)),
            new System.Data.DataColumn("DepartureTime", typeof(DateTime)) });
        dt.Rows.Add(1, "04/26/2018 14:10");
        dt.Rows.Add(2, "04/26/2018 05:00");
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }
}

VB.Net

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    If Not Me.IsPostBack Then
        Dim dt As System.Data.DataTable = New System.Data.DataTable()
        dt.Columns.AddRange(New System.Data.DataColumn(1) {New System.Data.DataColumn("Id", GetType(Integer)), New System.Data.DataColumn("DepartureTime", GetType(DateTime))})
        dt.Rows.Add(1, "04/26/2018 14:10")
        dt.Rows.Add(2, "04/26/2018 05:00")
        GridView1.DataSource = dt
        GridView1.DataBind()
    End If
End Sub

Screenshot