DetailsView

Discussion in 'ASP .Net' started by vbnetdev, Mar 21, 2006.

  1. vbnetdev

    vbnetdev Guest

    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.
    --
    Get a powerful web, database, application, and email hosting with KJM
    Solutions
    http://www.kjmsolutions.com
     
    vbnetdev, Mar 21, 2006
    #1
    1. Advertisements

  2. 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.)
     
    Steven Cheng[MSFT], Mar 22, 2006
    #2
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Murugan V via DotNetMonster.com

    How to add the DropDownList and TextBox Control in DetailsView

    Murugan V via DotNetMonster.com, Jan 8, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    702
    Murugan V via DotNetMonster.com
    Jan 8, 2005
  2. =?Utf-8?B?Q2VyaV9EYXZpZXM=?=

    Binding a textbox to a detailsview in asp.net 2.0

    =?Utf-8?B?Q2VyaV9EYXZpZXM=?=, Mar 22, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    1,019
    =?Utf-8?B?Q2VyaV9EYXZpZXM=?=
    Mar 22, 2005
  3. podong28
    Replies:
    1
    Views:
    1,957
    Brock Allen
    Apr 20, 2005
  4. Justin Rich

    Detailsview empty dataset insert

    Justin Rich, May 19, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    3,324
    Justin Rich
    May 19, 2005
  5. Feege
    Replies:
    0
    Views:
    559
    Feege
    Dec 20, 2005
Loading...

Share This Page