Manivel
Manivel

Reputation: 39

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.

enter image description here

After selecting the date.

enter image description here

I want this selected date to codebehind date variable.

Upvotes: 1

Views: 927

Answers (1)

ekad
ekad

Reputation: 14614

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)

Upvotes: 1

Related Questions