Solved

Error with Checkbox in Gridview For Boolean value

Posted on 2008-10-21
13
904 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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 13

Expert Comment

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

Accepted Solution

by:
sm394 earned 250 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 250 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sending an input value from a view to a controller in MVC 3 27
Change to file doesn't show up 16 75
linq .concat equivalent with expression syntax 4 22
Return array 3 20
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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

756 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