?
Solved

checkbox --- accessdb true or flase

Posted on 2011-05-05
24
Medium Priority
?
269 Views
Last Modified: 2012-05-11
Om trying to tick a checkbox if yes/no field in my accessdb the true

but it seems to check it no matter what?!?!

 Important <input type="checkbox" id="important"  checked="<%#Eval("important") %>" />

Open in new window

0
Comment
Question by:runnerjp2005
  • 14
  • 9
24 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 35699763
Try this

Important <input type="checkbox" id="important"  checked="<%# IIF(Eval("important")="Yes", True, False) %>" />
0
 

Author Comment

by:runnerjp2005
ID: 35699851
still both ticked and i did Important <input type="checkbox" id="important"  checked="<%# IF(Eval("important")="Yes", True, False) %>" />
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 35701977
If you set a label equal to Eval("important"), what does it return?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 13

Expert Comment

by:jeebukarthikeyan
ID: 35704040
hi,

check whats the value coming i n "important"

and also try IF(Eval("important").toLower()="yes"

Open in new window


jeebu
0
 

Author Comment

by:runnerjp2005
ID: 35704804
<asp:TextBox id="title" runat="server" Text='<%#Eval("important") %>' />

there was no output :S
0
 

Author Comment

by:runnerjp2005
ID: 35704812
Sorry it comes back as True
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 35704815
Hence the checkbox is checked. So there is no problem in the checkbox then. Should it be true?
0
 

Author Comment

by:runnerjp2005
ID: 35704901
important <input type="checkbox" id="Checkbox1"  checked="<%#IF(Eval("important")="True", True, False) %>" />

just to note i set it to = True

0
 

Author Comment

by:runnerjp2005
ID: 35704907
but if i set it to flase its still checked :S
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 35704919
Where do you set it false?
0
 

Author Comment

by:runnerjp2005
ID: 35704975
its just unticked in accessdb

Here is my screenshot and code.

  <form id="form1" runat="server">
 <div class="style1">
       <center>
        Edit Post<br />
        <asp:FormView ID="FormView1" runat="server" DataSourceID="AccessDataSource1">
        <ItemTemplate>
<asp:TextBox id="title" runat="server" Text='<%#Eval("Title") %>' /> <br />
<asp:TextBox id="post" runat="server" Text='<%#Eval("Post") %>' TextMode="MultiLine" />
Important<asp:TextBox id="TextBox1" runat="server" Text='<%#Eval("important") %>' /> <br />
 Locked      <asp:TextBox id="TextBox2" runat="server" Text='<%#Eval("forumlock") %>' /> <br />   
           <br />
          Important 


                  
        important <input type="checkbox" id="Checkbox1"  checked="<%#IF(Eval("important")="True", True, False) %>" />
      
           
          &nbsp; Locked <input type="checkbox" id="Checkbox2"  checked="<%# IF(Eval("forumlock")="True", True, False) %>" />
          </ItemTemplate>
        </asp:FormView>
        <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
            DataFile="~/forums/forum.mdb" SelectCommand="SELECT * FROM [forum] Where ID = @ID">
            <SelectParameters>
            <asp:QueryStringParameter Name="ID" QueryStringField="ID" />
            </SelectParameters>
        </asp:AccessDataSource></center>
    </div>
    </form>

Open in new window



untitled.bmp
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 35704983
>checked="<%#IF(Eval("important")="True", True, False) %>"

Its "IIF" function not "IF"

Also try

checked="<%= IIF(Eval("important")="True", True, False) %>"
0
 

Author Comment

by:runnerjp2005
ID: 35705100
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
.

thats what i fot now :S
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 35705118
Hmm. Try

checked="<%= IIF(Container.Eval("important")="True", True, False) %>"
0
 

Author Comment

by:runnerjp2005
ID: 35705170
BC30451: 'Container' is not declared. It may be inaccessible due to its protection level.


is there any way i can do it beihind the code and do

if val("important")="True" then
show checked tick box
else
show unticked textbox
end if
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 35705238
You have to check the value of important via the accessdatasource1. Does the page allowing modifying values?
0
 

Author Comment

by:runnerjp2005
ID: 35705265
>>>
You have to check the value of important via the accessdatasource1. Does the page allowing modifying values?

i dont understand :S

Here is the below page

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="editpostadmin.aspx.vb" Inherits="forums_editpostadmin" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Edit Post</title>
    </head>
<body>
    <form id="form1" runat="server">
 <div class="style1">
       <center>
        Edit Post<br />
        <asp:FormView ID="FormView1" runat="server" DataSourceID="AccessDataSource1">
        <ItemTemplate>
<asp:TextBox id="title" runat="server" Text='<%#Eval("Title") %>' /> <br />
<asp:TextBox id="post" runat="server" Text='<%#Eval("Post") %>' TextMode="MultiLine" />
Important<asp:TextBox id="TextBox1" runat="server" Text='<%#Eval("important") %>' /> <br />
 Locked      <asp:TextBox id="TextBox2" runat="server" Text='<%#Eval("forumlock") %>' /> <br />   
           <br />
          Important 


                  
        important <input type="checkbox" id="Checkbox1"  checked="<%= IIF(Container.Eval("important")="True", True, False) %>"  />
      
           
          &nbsp; Locked <input type="checkbox" id="Checkbox2"  checked="<%= IIF(Container.Eval("forumlock")="True", True, False) %>"  />
          </ItemTemplate>
        </asp:FormView>
        <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
            DataFile="~/forums/forum.mdb" SelectCommand="SELECT * FROM [forum] Where ID = @ID">
            <SelectParameters>
            <asp:QueryStringParameter Name="ID" QueryStringField="ID" />
            </SelectParameters>
        </asp:AccessDataSource></center>
    </div>
    </form>
</body>
</html>

Open in new window

0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 35705284
Try

If Formview1.DataItem("important") = "Yes"   'if not, try If Formview1.DataItem("important") = "True"
   Checkbox1.Checked = True
Else
   Checkbox1.Checked = False
End If
0
 

Author Comment

by:runnerjp2005
ID: 35705400
Protected Sub FormView1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.Load

    End Sub

it wont find checkbox 1...do i need to decalre it?
0
 

Author Comment

by:runnerjp2005
ID: 35705634
Ok update is i tried this:
    Protected Sub FormView1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.Load

        Dim Checkbox1 As CheckBox = CType(FormView1.Row.FindControl("Checkbox1"), CheckBox)

        If FormView1.DataItem("important") = "True" Then
            Checkbox1.Checked = True
        Else
            Checkbox1.Checked = False
        End If

    End Sub

Open in new window


and i get this error Object reference not set to an instance of an object.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 35705847
Use the page load not formview load event.

Checkbox1 is not inside a repeater or datalist so it should be accessible directly.
0
 

Author Comment

by:runnerjp2005
ID: 35706301
it does not show in pageload
0
 

Author Comment

by:runnerjp2005
ID: 35706331
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="editpostadmin.aspx.vb" Inherits="forums_editpostadmin" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Edit Post</title>
    </head>
<body>
    <form id="form1" runat="server">
 <div class="style1">
       <center>
          
        Edit Post<br />
        <asp:FormView ID="FormView1" runat="server" DataSourceID="AccessDataSource1">
        <ItemTemplate>
<asp:TextBox id="title" runat="server" Text='<%#Eval("Title") %>' /> <br />
<asp:TextBox id="post" runat="server" Text='<%#Eval("Post") %>' TextMode="MultiLine" />
Important<asp:TextBox id="TextBox1" runat="server" Text='<%#Eval("important") %>' /> <br />
 Locked      <asp:TextBox id="TextBox2" runat="server" Text='<%#Eval("forumlock") %>' /> <br />   
           <br /><asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
          Important 


                  
        important<asp:CheckBox ID="CheckBox1" runat="server" />
      
           
          &nbsp; Locked 
            <asp:CheckBox ID="CheckBox2" runat="server" />
          </ItemTemplate>
        </asp:FormView>
        <asp:CheckBox ID="CheckBox3" runat="server" />
        <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
            DataFile="~/forums/forum.mdb" SelectCommand="SELECT * FROM [forum] Where ID = @ID">
            <SelectParameters>
            <asp:QueryStringParameter Name="ID" QueryStringField="ID" />
            </SelectParameters>
        </asp:AccessDataSource></center>
    </div>
    
    </form>
</body>
</html>

Open in new window


i can find checkbox3 but nothing within  <asp:FormView ID="FormView1" runat="server" DataSourceID="AccessDataSource1">
0
 

Author Closing Comment

by:runnerjp2005
ID: 35706377
<asp:CheckBox ID="CheckBox2" runat="server" Checked='<%#Eval("forumlock") %>'/>

i did it!!!! for some reson it was set to input rather then checkbox!!!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question