如何从网格视图中的时间选择器中检索时间
本文关键字:时间 选择器 检索 视图 网格 | 更新日期: 2023-09-27 18:21:52
我有一个网格视图,里面有一个TimeSelector,但我该如何从网格视图中检索时间,因为如果通常是TextBox,我们将使用这个
Dim rbSelect As TextBox = DirectCast(GridView2.Cells(1).FindControl("TextBox"), TextBox)
那么我应该如何从gridview中的timeselector中检索时间呢?
时间选择器控件:<%@寄存器程序集="TimePicker"Namespace="MKB.TimePicker"TagPrefix="cc1"%>
<ItemTemplate>
<table style="width: 79%; height: 31px;">
<tr>
<td class="style1">
<asp:Label ID="Label1" runat="server" Text="Time to start:"></asp:Label>
</td>
<td>
<cc1:TimeSelector ID="TimeSelector3" runat="server" AllowSecondEditing="false" DisplaySeconds="False" Height="25px" MinuteIncrement="15" Width="150px" />
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button1" runat="server" Text="Button"
onclick="Button1_Click" />
</td>
</tr>
</table>
</ItemTemplate>
<ControlStyle Width="100px" />
<ItemStyle Width="210px" />
</asp:TemplateField>
所以这里有一些信息可以告诉你如何做到这一点:
-
添加对TimePicker.dll的引用。请在此处查看有关它的详细信息。我就是这个
-
在你正在工作的aspx页面上,你可以写。要查看有关如何制定register标记的更多信息,请参阅:
<%@ Register Assembly="TimePicker" Namespace="MKB.TimePicker" TagPrefix="mkb"%>
-
要使用
TimePicker
,也就是TimeSelector
(我知道这一点,因为我查看了.net reflector中的dll,请参阅此)。每页需要一个ScriptManager
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
-
要使用页面上的控件,请写入:
<mkb:TimeSelector ID="TimeSelector1" runat="server"></mkb:TimeSelector>
这就是在页面中添加单个TimeSelector
的方法。
以下是网格视图中TimeSelector
的完整示例:
默认.aspx
<%@ Register Assembly="TimePicker" Namespace="MKB.TimePicker" TagPrefix="mkb"%>
<%@ Page Title="Home Page" Language="vb" AutoEventWireup="false"
CodeBehind="Default.aspx.vb" Inherits="WebApplication1._Default" %>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:GridView ID="gvTest" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<mkb:TimeSelector ID="TimeSelector1" runat="server"></mkb:TimeSelector>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</form>
</body>
默认.aspx.vb
Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ls As New List(Of String)()
ls.Add("Test")
ls.Add("Test2")
gvTest.DataSource = ls
gvTest.DataBind()
End Sub
Private Sub gvTest_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvTest.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim picker As MKB.TimePicker.TimeSelector = DirectCast(e.Row.FindControl("TimeSelector1"), MKB.TimePicker.TimeSelector)
End If
End Sub
Private Sub Save()
For Each row As GridViewRow In gvTest.Rows
Dim picker As MKB.TimePicker.TimeSelector = DirectCast(row.FindControl("TimeSelector1"), MKB.TimePicker.TimeSelector)
Next
End Sub
End Class