Solved

Error with Checkbox in Gridview For Boolean value

Posted on 2008-10-21
13
898 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
  • 6
  • 5
  • 2
13 Comments
 
LVL 25

Expert Comment

by:apeter
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 13

Expert Comment

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

Accepted Solution

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

Author Comment

by:GravitaZ24
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 13

Expert Comment

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

Author Comment

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

Assisted Solution

by:sm394
sm394 earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
every field i meant
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now