Hello Morris,
As for the setting default/inital value for TextBox in the DetailsView's
Insert Mode. I would suggest you consider converting the certain Field into
TemplateField. Thus, the TextBox has a definte ID we can used to reference
it in code. And we can put some code in the DetailsView.ItemCreated Event,
if the "CurrentMode==Insert", you can find that TextBox and set a initial
value on it. Here is a simple test page fragment demonstrate on this:
======================
<asp
etailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataKeyNames="ProductCategoryID"
DataSourceID="SqlDataSource1" Height="50px" Width="125px"
OnItemCreated="DetailsView1_ItemCreated">
<Fields>
<asp:BoundField DataField="ProductCategoryID"
HeaderText="ProductCategoryID" InsertVisible="False"
ReadOnly="True" SortExpression="ProductCategoryID" />
<asp:TemplateField HeaderText="Name" SortExpression="Name">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("Name") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("Name") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Bind("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True"
ShowInsertButton="True" />
</Fields>
</asp
etailsView>
==========================
==============
protected void DetailsView1_ItemCreated(object sender, EventArgs e)
{
if (DetailsView1.CurrentMode == DetailsViewMode.Insert)
{
TextBox txt = DetailsView1.FindControl("TextBox1") as TextBox;
if (txt != null)
{
txt.Text = "Default text value.....";
}
}
}
===================
Hope this helps some. If you have any other concerns here, please feel free
to let me know.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.