Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net Gridview:如何通过dropdownlist刷新时间选择器值?_Asp.net_Gridview_Drop Down Menu_Timepicker - Fatal编程技术网

Asp.net Gridview:如何通过dropdownlist刷新时间选择器值?

Asp.net Gridview:如何通过dropdownlist刷新时间选择器值?,asp.net,gridview,drop-down-menu,timepicker,Asp.net,Gridview,Drop Down Menu,Timepicker,在我的gridview中,我使用MKB Timepicker让用户输入时间。现在我想在gridview中添加一个DropDownList,当用户选择DropDownList时,它会自动刷新时间选择器值(开始时间、结束时间)。但我不知道在更新/编辑模板时如何刷新值。请帮忙 谢谢 乔 ASP代码: <EditItemTemplate> <asp:DropDownList ID="ddl1_shifttype" runat ="server" AutoPostBack ="true

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

谢谢 乔

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> 

在DropDownList SelectedIndexChanged事件中,编写代码以使用FindControl刷新时间选择器。

问题已解决。代码如下:

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

谢谢。我在SelectedIndexChanged事件中为测试分配了一个值,但它不起作用。如何使用FindControl分配timeselector值?坦斯克
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