Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old November 28th, 2006, 12:48 PM
Authorized User
Join Date: Oct 2006
Posts: 20
Thanks: 1
Thanked 0 Times in 0 Posts
Default DetailsView checkbox default appearance

I'm working with a GridView / DetailsView combo to maintain records in an Access database. One of the shortcomings of DetailsView is the difficulty in establishing default values for fields on the new records. But I have found a way to make that work by using the data binding event. The following code is how I set values, one for a textbox and one for a checkbox.

Protected Sub DetailsView1_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs) Handles DetailsView1.PreRender
If DetailsView1.CurrentMode = DetailsViewMode.Insert Then
    Dim ThisControl As TextBox
    ThisControl = DetailsView1.FindControl("InsertDays")
    ThisControl.Text = "1"
    Dim ThisCheck As Checkbox
    ThisCheck = DetailsView1.FindControl("InsertRegisterOnline")
    ThisCheck.Checked = True
    End if
End Sub

My current problem is the checkbox. I managed to give it an ID by using a templatefield (you can't assign an ID to a simple CheckBoxField). So inside the DetailsView, I now use:

<asp:TemplateField HeaderText="Register online?">
        <asp:Checkbox ID="RegisterOnlineLabel" Runat="Server" Checked='<%# Eval("RegisterOnline") %>' />
        <asp:Checkbox ID="InsertRegisterOnline" runat="server" Checked='<%# Bind("RegisterOnline")%>' />
        <asp:Checkbox ID="EditRegisterOnline" runat="server" Checked='<%# Bind("RegisterOnline")%>' />

This sort of works, but when I am in read mode, the checkbox looks as though it is editable (the user can click and change the checkbox setting). The changes do not carry through to the database, of course.

At the moment I need some way of making the checkbox appear read-only when the record has been selected and is in fact read-only.

Frankly, I'll accept any other scheme to do this, because all of this code is just a workaround for the absence of a simple method of setting default values when in insert mode. (ASP sure was a lot simpler to program!)

Old November 29th, 2006, 12:27 PM
Authorized User
Join Date: Sep 2006
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts

Hi , jpullam
make the checkbox enabled property to false .
It will work

Old November 29th, 2006, 02:37 PM
Authorized User
Join Date: Oct 2006
Posts: 20
Thanks: 1
Thanked 0 Times in 0 Posts

Great, that worked, thanx a lot.

Don't know how I could miss something that simple!

Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting a DetailsView Insert default value jpullam ASP.NET 2.0 Basics 13 April 7th, 2014 02:19 AM
struts-html: checkbox default checked RatanKumar Struts 1 November 5th, 2007 05:49 AM
Mailto Form Appearance Ron Howerton HTML Code Clinic 5 September 29th, 2007 11:59 PM
checkbox checked by default by html:checkbox sachin.tathod Struts 3 December 4th, 2006 03:41 PM
Datalist with checkbox -- how to default checked? jobber99 ASP.NET 1.0 and 1.1 Basics 1 January 30th, 2006 02:52 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.