简体   繁体   中英

How to get the date value from date control that is placed in gridview?

In my ASP.NET project I have one gridview and I have placed the DateControl in gridview using TemplateField. My question is how can I get the Selected Date value? I'm doing my code in VB

My ASP code is

<asp:TemplateField HeaderText="Release Date" ControlStyle-Width="100">
      <ItemTemplate>
           <uc1:DateControl ID="UCReleaseDate" runat="server" />
      </ItemTemplate>
</asp:TemplateField>

And my vb code is (not working)

 Dim dtReleaseDate As DateTime
dtReleaseDate = DateTime.Parse(GVMaintainBankChallon.Rows(iGVRowIndex).FindControl  ("UCReleaseDate").ToString)

I want to get the Selected Date value in dtReleaseDate variable.. Hope someone will understand this problem and help me..

The gridview image is shown below.

在此处输入图片说明

After selecting the date.

在此处输入图片说明

I want this selected date to codebehind date variable.

As per comment below, DateControl has a string property named DateValue . Assuming that the date is in MM/dd/yyyy format, this code should work

Dim dateFromControl As String = CType(GVMaintainBankChallon.Rows(iGVRowIndex).FindControl("UCReleaseDate"), DateControl).DateValue

Dim dtReleaseDate As DateTime
dtReleaseDate = DateTime.ParseExact(dateFromControl, "MM/dd/yyyy", Nothing)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM