Solved

Error with Checkbox in Gridview For Boolean value

Posted on 2008-10-21
13
905 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using sample Autorize.net c# simple example 1 55
How does this modal work? 3 33
Datagridview column resizing 8 28
Need Help With GDI+ in VB.Net 8 41
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

739 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