DetailsView

V

vbnetdev

I need to customize the DetailsView New record (insert) so that it gets the
maximum value of ROWID and adds 1, places that value in the textbox and
makes it read only.

Also, I have a field called "DATEEVENT". I would like to place a calendar
control there instead of the textbox that is shown.

Thanks for any help.
 
S

Steven Cheng[MSFT]

Hi Vbnetdev,

Welcome to the ASPNET newsgroup.

As for the two detailsview questions you mentioned, I think both of them
require additioal customization on the columns/fields. For such scenario,
it's better to use TemplateFields instead of the default BoundField. In vs
2005's design-view, the DetailsView's smartTag wizard provide the UI to let
us convert a certain boundfield to a templatefield. After that, we can do
some customization on the template of the certain column/field. e.g: we can
add some addtional controls into the template (like calendar...).

For your two questions, the first one (set the max rowID to the textbox in
insert template) can be done by registering the DetailsView' ItemCreated
event, and add some code to manually query the max rowID allowed from the
database and assign the value to the insert template's certain textbox. e.g:

protected void DetailsView1_ItemCreated(object sender, EventArgs e)
{
if (DetailsView1.CurrentMode == DetailsViewMode.Insert)
{
//find the certain control and assign the value queried from db
to it
}
}


For the second question, we can put a calendar in the InsertTemplate, and
use its SelectedDatechanged event to update the selected date to the
certain textbox in the InsertItemtemplate. e.g;

==========detailsview's template field========
<asp:TemplateField HeaderText="Description" SortExpression="Description">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("Description") %>'></asp:TextBox><br />
<asp:Calendar ID="cld1" runat="server"
OnSelectionChanged="cld1_SelectionChanged"></asp:Calendar>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("Description") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Bind("Description") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True"
ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
===================

=======calendar's event handler===========
protected void cld1_SelectionChanged(object sender, EventArgs e)
{
Calendar cld1 = sender as Calendar;

TextBox txt = cld1.NamingContainer.FindControl("TextBox1") as
TextBox;

txt.Text = cld1.SelectedDate.ToString("yyyy-MM-dd");
}
==========================

Hope this helps.

regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

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

Forum statistics

Threads
473,754
Messages
2,569,526
Members
44,997
Latest member
mileyka

Latest Threads

Top