Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I give the following Code in Gridview
XML
<asp:TemplateField HeaderText="MAP" SortExpression="UCM_MAPPED">
              <EditItemTemplate>
                  <asp:CheckBox ID="maphdr" runat="server" Checked='<%# Bind("UCM_MAPPED") %>' />
              </EditItemTemplate>
              <ItemTemplate>
                  <asp:CheckBox ID="ucm_mapped" runat="server" Checked='<%# Bind("UCM_MAPPED") %>' />
              </ItemTemplate>
          </asp:TemplateField>


But the error is occured 'Specified cast is not valid'

I don't Know, Why it is? Please help me......
Posted
Comments
Philip Stuyck 1-Aug-12 3:10am    
On which line is this error occurring ? Is it the sort expression or the bindings ?
devausha 1-Aug-12 3:12am    
In this line With in the 'itemtemplete' When I remove "Checked='<%# Bind("UCM_MAPPED") %>' " it, The error is not displaying. But I want bind the data of table.
<itemtemplate><asp:CheckBox ID="ucm_mapped" runat="server" Checked='<%# Bind("UCM_MAPPED") %>' />
Prasad J 1-Aug-12 3:15am    
Ensure the value in the field [UCM_MAPPED] returns True or False not 0 or 1
devausha 1-Aug-12 3:15am    
In my database has 0 or 1, how to set it true or false
Prasad J 1-Aug-12 3:23am    
Change your query something as follows:
SELECT [field1], [field2],
CASE UCM_MAPPED WHEN 1 THEN 'True' ELSE 'False' End as UCM_MAPPED, ....

1 solution

Try this
<asp:checkbox id="maphdr" runat="server" checked="<%# Boolean.Parse(Eval("UCM_MAPPED").ToString()) %>" xmlns:asp="#unknown" />
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900