Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Error with Checkbox in Gridview For Boolean value

Posted on 2008-10-21
13
Medium Priority
?
908 Views
Last Modified: 2013-11-05
I'm trying to put a checkbox into the gridview, and i want it to send a True or a False value into the database. I keep getting an error
Compiler Error Message: CS0103: The name 'True' does not exist in the current context

Source Error:

Line 227:                  <asp:templatefield HeaderText="Send Notification To Tim">
Line 228:                        <EditItemTemplate>
Line 229:                    <asp:CheckBox ID="chkOverrideAllow" runat="server" Checked='<%# (Eval("edit_override") == "True") ? True : False %>'/>
Line 230:                    </EditItemTemplate>
Line 231:                        <ItemTemplate>

I'm not sure what is going wrong

<asp:templatefield HeaderText="Send Notification To Tim">
				<EditItemTemplate>
                    <asp:CheckBox ID="chkOverrideAllow" runat="server" Checked='<%# (Eval("Send_Tim") == "True") ? True : False %>'/>
                    </EditItemTemplate>
				<ItemTemplate>
				<asp:label id="LabelTim" runat="server" Text='<%# Bind("Send_Tim") %>'></asp:label>
                  </ItemTemplate>

Open in new window

0
Comment
Question by:GravitaZ24
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 2
13 Comments
 
LVL 25

Expert Comment

by:apeter
ID: 22769861
is it lower case "true" you should compare ? DId you checked what exactly the value is coming ?

I think, directly assign the value instead of using tenary operator, it should work fine.
 <asp:CheckBox ID="chkOverrideAllow" runat="server" Checked='<%# (Eval("edit_override")'/>
0
 

Author Comment

by:GravitaZ24
ID: 22770031
Hi!
I'm getting "Specified Cast is not Valid" error when i click the update button on Gridview

<asp:templatefield HeaderText="Send Notification To Tim">
                        <EditItemTemplate>
                    <asp:CheckBox ID="chkOverrideAllow" runat="server" Checked='<%#(Eval("Send_Tim")) %>'/>
                </EditItemTemplate>
0
 
LVL 25

Expert Comment

by:apeter
ID: 22770216
One way it override RowDataBound Event of Gridview like below and set the checked property in code behind. Else what is the value of <%#(Eval("Send_Tim")) %> ? hope it is "true"

void CustomersGridView_RowDataBound(Object sender, GridViewRowEventArgs e)
  {
    if(e.Row.RowType == DataControlRowType.DataRow)
    {
      // Display the company name in italics.
      e.Row.Cells[1].Text = "<i>" + e.Row.Cells[1].Text + "</i>";
    }
  }
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 13

Expert Comment

by:sm394
ID: 22770220
<%# Eval("Send").ToString().Equals("True") ? true : false%>
0
 
LVL 13

Accepted Solution

by:
sm394 earned 750 total points
ID: 22770360
sorry typo in above
this will do
Checked='<%# Eval("Send_Tim").ToString().Equals("True") ? true :false %>'
0
 

Author Comment

by:GravitaZ24
ID: 22770383
Thanks again guys, sm394, i tried what you did, I didn't get an error, but nothing was showing up in the database field
0
 
LVL 13

Expert Comment

by:sm394
ID: 22770595
A- Do you get checkbox checked or unchecked
B-  what values 'Send_Tim' field has in database table
0
 

Author Comment

by:GravitaZ24
ID: 22770614
A- the checkbox is intially unchecked.
B- The fields are all "Null"
0
 
LVL 13

Assisted Solution

by:sm394
sm394 earned 750 total points
ID: 22770827
kool
with this snipet
Checked='<%# Eval("Send_Tim").ToString().Equals("True") ? true :false %>'
if field val is True checkbox will be checked
if field val is Null or False check box will be unchecked

could you tell us a bit more what you trying to achieve
0
 

Author Comment

by:GravitaZ24
ID: 22770931
Eventually what I want to achieve is, my boss asked me to have a field in the database be checked to true or false if a problem is to be sent to a certain person (Tim). When this field is true, i'm going to have a trigger send an e-mail to the person notifying him.
0
 
LVL 13

Expert Comment

by:sm394
ID: 22771171
I am not sure for sending email you will use Database mail /trigger or C# email options but you can get
the status of Send_Tim field on RowDataBound event of gridview
try the link below

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx 
 http://authors.aspalliance.com/aspxtreme/sys/web/ui/webcontrols/GridViewClassRowDataBound.aspx
0
 

Author Comment

by:GravitaZ24
ID: 22776614
Thank you for the help! I was able to figure out he problem was that the null fields already in the table were messing everything up, So i just inserted "False" into every table!
0
 

Author Comment

by:GravitaZ24
ID: 22776622
every field i meant
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

730 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