0

I'm trying to have a label in the edititemtemplate of my gridview show the current date and time when the user clicks the edit linkbutton. When I put date.now in the data binding box, I can see the result I want, but when I click update, I get an error that the field can't be null. It works fine when I try it for the footer row, but not the edit row. Here's the footer row code that works:

'Get Time Recorded
Dim lblFtrTimeRecorded As Label = GridView1.FooterRow.FindControl("lblFtrTimeRecorded")
lblFtrTimeRecorded.Text = Date.Now

Here's the template field .aspx code:

        <asp:TemplateField HeaderText="TimeRecorded" SortExpression="TimeRecorded">
            <EditItemTemplate>
                <asp:Label ID="lblEditTimeRecorded" runat="server" 
                    Text='<%# Bind("TimeRecorded") %>'></asp:Label>
            </EditItemTemplate>
            <FooterTemplate>
                <asp:Label ID="lblFtrTimeRecorded" runat="server"></asp:Label>
            </FooterTemplate>
            <ItemTemplate>
                <asp:Label ID="lblTimeRecorded" runat="server" 
                    Text='<%# Bind("TimeRecorded") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>

Any help is greatly appreciated!

Tonigafa
  • 1
  • 1

1 Answers1

0

Write this code :

Dim lblFtrTimeRecorded As Label = GridView1.Rows[GridView1.EditIndex].FindControl("lblFtrTimeRecorded")
lblFtrTimeRecorded.Text = Date.Now
pankeel
  • 1,138
  • 1
  • 10
  • 22