Gridview:如何通过下拉列表刷新Timepicker值?

发布于 2024-11-26 01:54:48 字数 2110 浏览 3 评论 0原文

1

在我的 gridview 中,我使用 MKB Timepicker 让用户输入时间。现在我想在gridview中添加一个下拉列表,当用户选择下拉列表时,它会自动刷新时间选择器值(开始时间,结束时间)。但我不知道如何在行更新/编辑模板时刷新该值。请帮忙。

谢谢 Joe

ASP 代码:

<EditItemTemplate>
<asp:DropDownList ID="ddl1_shifttype" runat ="server"  AutoPostBack ="true" DataSourceID="SqlDataSource2" DataTextField ="en_name" DataValueField ="shift_type_key" SelectedValue='<%# Bind("Col1_ShiftType") %>' OnSelectedIndexChanged ="ddl1_shifttype_SelectedIndexChanged"></asp:DropDownList>
From:
<MKB:TimeSelector ID="Col1_StartTime" runat="server" DisplaySeconds="False" MinuteIncrement="1"  BorderColor="Silver" 
                            Date="" SelectedTimeFormat="Twelve" 
                            Hour='<%#DataBinder.Eval(Container.DataItem, "Col1_StartTimeHr")%>' 
                            Minute ='<%#DataBinder.Eval(Container.DataItem, "Col1_StartTimeMin")%>'
                            AmPm ='<%#DataBinder.Eval(Container.DataItem, "Col1_StartTimeAMPM")%>'></MKB:TimeSelector>
To:
<MKB:TimeSelector ID="Col1_EndTime" runat="server" DisplaySeconds="False"  MinuteIncrement="1" BorderColor="Silver" 
                            Date="" SelectedTimeFormat="Twelve"                                 
                            Hour='<%#DataBinder.Eval(Container.DataItem, "Col1_EndTimeHr")%>' 
                            Minute ='<%#DataBinder.Eval(Container.DataItem, "Col1_EndTimeMin")%>'
                            AmPm ='<%#DataBinder.Eval(Container.DataItem, "Col1_EndTimeAMPM")%>'></MKB:TimeSelector>                                 
</EditItemTemplate> 

SelectIndexChange 事件:

Protected Sub ddl1_shifttype_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl1_shifttype.SelectedIndexChanged
'Testing
    Col1_StartTime.Hour = "09"
    Col1_StartTime.Minute = "33"
    Col1_StartTime.AmPm = TimeSelector.AmPmSpec.PM        
End Sub

1

In my gridview, I had used MKB Timepicker to let user input time. Now I want to add a dropdownlists in the gridview, when user select dropdownlists, it will automatically refresh the timepicker value (start time, end time). But I have no idea how to refresh the value when rowupdating/edit template. Please help.

Thanks
Joe

ASP code:

<EditItemTemplate>
<asp:DropDownList ID="ddl1_shifttype" runat ="server"  AutoPostBack ="true" DataSourceID="SqlDataSource2" DataTextField ="en_name" DataValueField ="shift_type_key" SelectedValue='<%# Bind("Col1_ShiftType") %>' OnSelectedIndexChanged ="ddl1_shifttype_SelectedIndexChanged"></asp:DropDownList>
From:
<MKB:TimeSelector ID="Col1_StartTime" runat="server" DisplaySeconds="False" MinuteIncrement="1"  BorderColor="Silver" 
                            Date="" SelectedTimeFormat="Twelve" 
                            Hour='<%#DataBinder.Eval(Container.DataItem, "Col1_StartTimeHr")%>' 
                            Minute ='<%#DataBinder.Eval(Container.DataItem, "Col1_StartTimeMin")%>'
                            AmPm ='<%#DataBinder.Eval(Container.DataItem, "Col1_StartTimeAMPM")%>'></MKB:TimeSelector>
To:
<MKB:TimeSelector ID="Col1_EndTime" runat="server" DisplaySeconds="False"  MinuteIncrement="1" BorderColor="Silver" 
                            Date="" SelectedTimeFormat="Twelve"                                 
                            Hour='<%#DataBinder.Eval(Container.DataItem, "Col1_EndTimeHr")%>' 
                            Minute ='<%#DataBinder.Eval(Container.DataItem, "Col1_EndTimeMin")%>'
                            AmPm ='<%#DataBinder.Eval(Container.DataItem, "Col1_EndTimeAMPM")%>'></MKB:TimeSelector>                                 
</EditItemTemplate> 

SelectIndexChange Event:

Protected Sub ddl1_shifttype_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl1_shifttype.SelectedIndexChanged
'Testing
    Col1_StartTime.Hour = "09"
    Col1_StartTime.Minute = "33"
    Col1_StartTime.AmPm = TimeSelector.AmPmSpec.PM        
End Sub

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蝶舞 2024-12-03 01:54:48

在 DropDownList SelectedIndexChanged 事件中,编写代码以使用 FindControl 刷新 TimePicker。

In the DropDownList SelectedIndexChanged Event, Write the Code to Refresh the TimePicker by using FindControl.

紫﹏色ふ单纯 2024-12-03 01:54:48

问题解决了。以下是代码:

Protected Sub ddl1_shifttype_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl1_shifttype.SelectedIndexChanged
    Dim var As String = DirectCast(sender, DropDownList).SelectedValue
    Dim tm1 As TimeSelector = DirectCast(DirectCast(sender, DropDownList).Parent.Parent.FindControl("Col1_StartTime"), TimeSelector)
    Dim tm2 As TimeSelector = DirectCast(DirectCast(sender, DropDownList).Parent.Parent.FindControl("Col1_EndTime"), TimeSelector)
    Dim cmd As New System.Data.SqlClient.SqlCommand
    Dim sql As String
    Dim reader As System.Data.SqlClient.SqlDataReader
    Dim ST As DateTime
    Dim ET As DateTime

    lb_ddl1.Text = var

    Using conn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("hris_shiftdutyConnectionString").ConnectionString)
        conn.Open()
        cmd.Connection = conn
        sql = "SELECT * from Tshift_type where shift_type_key='" & var & "';"
        cmd.CommandText = sql
        reader = cmd.ExecuteReader()
        If reader.Read() Then
            ST = reader("start_time")
            ET = reader("end_time")
        End If

        conn.Close()
        reader.Close()
    End Using

    If ST.Hour > 12 Then
        tm1.Hour = ST.Hour - 12
        tm1.AmPm = TimeSelector.AmPmSpec.PM
    Else
        tm1.Hour = ST.Hour
        tm1.AmPm = TimeSelector.AmPmSpec.AM
    End If
    tm1.Minute = ST.Minute

    If ET.Hour > 12 Then
        tm2.Hour = ET.Hour - 12
        tm2.AmPm = TimeSelector.AmPmSpec.PM
    Else
        tm2.Hour = ET.Hour
        tm2.AmPm = TimeSelector.AmPmSpec.AM
    End If
    tm2.Minute = ET.Minute

    'Dropdownlists = 'Select'
    If var = 0 Then
        tm1.Hour = "12"
        tm1.Minute = "00"
        tm1.AmPm = TimeSelector.AmPmSpec.AM
        tm2.Hour = "12"
        tm2.Minute = "00"
        tm2.AmPm = TimeSelector.AmPmSpec.AM
    End If

End Sub

Problem solved. the following are the code:

Protected Sub ddl1_shifttype_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl1_shifttype.SelectedIndexChanged
    Dim var As String = DirectCast(sender, DropDownList).SelectedValue
    Dim tm1 As TimeSelector = DirectCast(DirectCast(sender, DropDownList).Parent.Parent.FindControl("Col1_StartTime"), TimeSelector)
    Dim tm2 As TimeSelector = DirectCast(DirectCast(sender, DropDownList).Parent.Parent.FindControl("Col1_EndTime"), TimeSelector)
    Dim cmd As New System.Data.SqlClient.SqlCommand
    Dim sql As String
    Dim reader As System.Data.SqlClient.SqlDataReader
    Dim ST As DateTime
    Dim ET As DateTime

    lb_ddl1.Text = var

    Using conn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("hris_shiftdutyConnectionString").ConnectionString)
        conn.Open()
        cmd.Connection = conn
        sql = "SELECT * from Tshift_type where shift_type_key='" & var & "';"
        cmd.CommandText = sql
        reader = cmd.ExecuteReader()
        If reader.Read() Then
            ST = reader("start_time")
            ET = reader("end_time")
        End If

        conn.Close()
        reader.Close()
    End Using

    If ST.Hour > 12 Then
        tm1.Hour = ST.Hour - 12
        tm1.AmPm = TimeSelector.AmPmSpec.PM
    Else
        tm1.Hour = ST.Hour
        tm1.AmPm = TimeSelector.AmPmSpec.AM
    End If
    tm1.Minute = ST.Minute

    If ET.Hour > 12 Then
        tm2.Hour = ET.Hour - 12
        tm2.AmPm = TimeSelector.AmPmSpec.PM
    Else
        tm2.Hour = ET.Hour
        tm2.AmPm = TimeSelector.AmPmSpec.AM
    End If
    tm2.Minute = ET.Minute

    'Dropdownlists = 'Select'
    If var = 0 Then
        tm1.Hour = "12"
        tm1.Minute = "00"
        tm1.AmPm = TimeSelector.AmPmSpec.AM
        tm2.Hour = "12"
        tm2.Minute = "00"
        tm2.AmPm = TimeSelector.AmPmSpec.AM
    End If

End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文