Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old November 28th, 2006, 11:48 AM
Authorized User
 
Join Date: Oct 2006
Location: Toronto, Ontario, Canada.
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?">
    <ItemTemplate>
        <asp:Checkbox ID="RegisterOnlineLabel" Runat="Server" Checked='<%# Eval("RegisterOnline") %>' />
        </ItemTemplate>
    <InsertItemTemplate>
        <asp:Checkbox ID="InsertRegisterOnline" runat="server" Checked='<%# Bind("RegisterOnline")%>' />
        </InsertItemTemplate>
    <EditItemTemplate>
        <asp:Checkbox ID="EditRegisterOnline" runat="server" Checked='<%# Bind("RegisterOnline")%>' />
        </EditItemTemplate>
    </asp:TemplateField>

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!)


  #2 (permalink)  
Old November 29th, 2006, 11:27 AM
Authorized User
 
Join Date: Sep 2006
Location: , , India.
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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


  #3 (permalink)  
Old November 29th, 2006, 01:37 PM
Authorized User
 
Join Date: Oct 2006
Location: Toronto, Ontario, Canada.
Posts: 20
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Great, that worked, thanx a lot.

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

 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 04: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 02:41 PM
Datalist with checkbox -- how to default checked? jobber99 ASP.NET 1.0 and 1.1 Basics 1 January 30th, 2006 01:52 PM



All times are GMT -4. The time now is 07:51 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.