Retrieving fields with default values in ASP.NET 2.0 in Postback

C

cjbland

First off I apologize if this has been discussed before, I'm not
certain how to search for what I'm looking for so I figured I'd throw
this out there and see what I got.

I am working with a DetailsView (Insert mode) in ASP.NET 2.0 and one of
the fields I give a default value.

<asp:DetailsView ....>
<asp:TemplateField HeaderText="Date Entered"
SortExpression="d_entered">
<InsertItemTemplate>
<asp:TextBox ID="DateEntered" name="DateEntered" Text='<%# DateTime.Now
%>' ReadOnly="false" runat="server" />
</InsertItemTemplate
</asp:TemplateField>
.........
</asp:DetailsView>

When I click the insert button all of the values of my form are
returned except for the date entered. I viewed the source of my main
page and all of my other inputs have an id of "DetailsView1$ctl0x"
where x is a number. The ID for my date field is
"DetailsView1$DateEntered".

In my debugging I've created a few labels and I am setting them via:

protected void DetailsView1_ItemInserting(Object sender,
DetailsViewInsertEventArgs e)
{
a.Text = e.Values["serial_no"].ToString();
b.Text = e.Values["barcode"].ToString();
c.Text = e.Values["DateEntered"].ToString();
}

The page errors on the "c.Text = ..." line and it says that
"DateEntered" doesn't exist. I am obviously missing something here,
does any one have any input? Thanks in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top