| |

VerySource

 Forgot password?
 Register
Search
View: 714|Reply: 2

Please masters (an ASP.NET problem)

[Copy link]

2

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-19 00:20:01
| Show all posts |Read mode
Server error in "/ WedUser" application.
-------------------------------------------------- ------------------------------
 
The specified conversion is invalid.
Explanation: An unhandled exception occurred during the execution of the current web request. Check the stack trace for more information about the error and where it originated in the code.
 
Exception Details: System.InvalidCastException: The specified conversion is invalid.
 
Source error:
  <asp: GridView ID = "UserView" Width = "100%" runat = "server"
         AutoGenerateColumns = "false">
         <Columns>
           </ asp: TemplateField>
Line 32: <asp: TemplateField HeaderText = "is the administrator"> <ItemTemplate>
Line 33: <asp: CheckBox ID = "IsAdminCheck" Enabled = "false" runat = "server" Checked = '<% # DataBinder.Eval (Container.DataItem, "IsAdmin")%>' />
Line 34: </ ItemTemplate>
Line 35: </ asp: TemplateField>
     </ Columns>
        </ asp: GridView>

 Is this statement wrong: Checked = '<% # DataBinder.Eval (Container.DataItem, "IsAdmin")%>', because checked = "true", it seems like <% # DataBinder.Eval (Container.DataItem, "IsAdmin ")%> Cannot be converted to true!
Reply

Use magic Report

0

Threads

4

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-25 16:36:01
| Show all posts
It's like this ... the bound data must be true or false. And it can't have null values.
Reply

Use magic Report

0

Threads

73

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-1-25 17:45:02
| Show all posts
Not already at http://community.csdn.net/Expert/topic/5271/5271652.xml?temp=.2638513
Did you answer it?
Checked = '<% # (bool) DataBinder.Eval (Container.DataItem, "IsAdmin")%>'
Change to
Checked = '<% # checkAdmin (DataBinder.Eval (Container.DataItem, "IsAdmin"))%>'

Add a function in the background:
public bool checkAdmin (object fg) {
bool returnValue;
try {
    returnValue = Convert.ToBoolean (fg);
  }
catch (Exception) {
  returnValue = false;
}
return returnValue;
}
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list