HI
I have the following code for a grid that i'm using to manage Users. I created a custom edit form with a few textobxes and a checkbox, this works 100% when editing an item, however i get an error(Invalid Cast Exception) when trying to create a new User, this error is thrown while the custom form is being loaded.
I know that this is caused by the asp checkbox that i'm using in the edit form, Please assist me.
Thanks in advance :)
I have the following code for a grid that i'm using to manage Users. I created a custom edit form with a few textobxes and a checkbox, this works 100% when editing an item, however i get an error(Invalid Cast Exception) when trying to create a new User, this error is thrown while the custom form is being loaded.
I know that this is caused by the asp checkbox that i'm using in the edit form, Please assist me.
Thanks in advance :)
| <%@ Page Language="C#" AutoEventWireup="true" CodeFile="AdminPage.aspx.cs" Inherits="AddEditUsers" %> |
| <%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %> |
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| <html xmlns="http://www.w3.org/1999/xhtml"> |
| <head runat="server"> |
| <title>All Users</title> |
| <style type="text/css"> |
| .style1 |
| { |
| width: 100%; |
| height: 68px; |
| } |
| </style> |
| </head> |
| <body> |
| <form id="form1" runat="server"> |
| <asp:ScriptManager ID="ScriptManager1" runat="server"> |
| </asp:ScriptManager> |
| <div> |
| <table class="style1"> |
| <tr> |
| <td> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" |
| DataSourceID="SqlDataSource1" GridLines="None" |
| Skin="Vista" AllowAutomaticDeletes="True" AllowAutomaticUpdates="true" |
| AllowAutomaticInserts="true" AllowMultiRowEdit="True"> |
| <MasterTableView datakeynames="UserId" datasourceid="SqlDataSource1" EditMode="PopUp" commanditemdisplay="Top" > |
| <RowIndicatorColumn> |
| <HeaderStyle Width="20px"></HeaderStyle> |
| </RowIndicatorColumn> |
| <ExpandCollapseColumn> |
| <HeaderStyle Width="20px"></HeaderStyle> |
| </ExpandCollapseColumn> |
| <Columns> |
| <telerik:GridButtonColumn ConfirmText="Are You Sure You Want To Delete This User?" ButtonType="ImageButton" CommandName="Delete" Text="Delete" UniqueName="DeleteColumn1"> |
| <HeaderStyle Width="20px" /> |
| <ItemStyle HorizontalAlign="Center" /> |
| </telerik:GridButtonColumn> |
| <telerik:GridBoundColumn DataField="UserId" DataType="System.Int32" |
| HeaderText="UserId" ReadOnly="True" SortExpression="UserId" UniqueName="UserId" Visible="false"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="UserName" HeaderText="User Name" |
| SortExpression="UserName" UniqueName="UserName"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Password" HeaderText="Password" |
| SortExpression="Password" UniqueName="Password"> |
| </telerik:GridBoundColumn> |
| <telerik:GridCheckBoxColumn DataField="IsAdmin" HeaderText="Administrator" |
| DataType="System.Boolean"> |
| </telerik:GridCheckBoxColumn> |
| <telerik:GridEditCommandColumn ButtonType="ImageButton"> |
| </telerik:GridEditCommandColumn> |
| <telerik:GridHyperLinkColumn></telerik:GridHyperLinkColumn> |
| </Columns> |
| <EditFormSettings EditFormType="Template"> |
| <EditColumn UniqueName="EditCommandColumn1"></EditColumn> |
| <FormTemplate> |
| <table id="EditTable" cellspacing="1" cellpadding="1" border="0"> |
| <tr> |
| <td>User Name</td> |
| <td> <asp:TextBox ID="txtUserName" runat="server" MaxLength="10" Text='<%#Bind("UserName") %>'></asp:TextBox></td> |
| </tr> |
| <tr> |
| <td>Password</td> |
| <td> <asp:TextBox ID="txtPassword" runat="server" MaxLength="15" Text='<%#Bind("Password") %>'></asp:TextBox></td> |
| </tr> |
| <tr> |
| <td></td> |
| <td> <asp:CheckBox ID="chkIsAdmin" runat="server" Text="Administrator" Checked='<%#Bind("IsAdmin") %>'></asp:CheckBox></td> |
| </tr> |
| <tr> |
| <td><asp:Button id="btnUpdate" runat="server" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'/></td> |
| <td><asp:Button ID="btnCancel" runat="server" CausesValidation="false" CommandName="cancel" Text="Cancel"/></td> |
| </tr> |
| </table> |
| </FormTemplate> |
| </EditFormSettings> |
| </MasterTableView> |
| <ClientSettings> |
| <Selecting AllowRowSelect="True" /> |
| </ClientSettings> |
| <FilterMenu EnableTheming="True"> |
| <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> |
| </FilterMenu> |
| </telerik:RadGrid> |
| <asp:SqlDataSource ID="SqlDataSource1" runat="server" |
| ConflictDetection="CompareAllValues" |
| ConnectionString="<%$ ConnectionStrings:lawsocConnectionString %>" |
| DeleteCommand="DELETE FROM [tbUsers2] WHERE [UserId] = @original_UserId AND [UserName] = @original_UserName AND [Password] = @original_Password AND [IsAdmin] = @original_IsAdmin" |
| InsertCommand="INSERT INTO [tbUsers2] ([UserName], [Password], [IsAdmin]) VALUES (@UserName, @Password, @IsAdmin)" |
| OldValuesParameterFormatString="original_{0}" |
| SelectCommand="SELECT [UserId], [UserName], [Password], [IsAdmin] FROM [tbUsers2]" |
| UpdateCommand="UPDATE [tbUsers2] SET [UserName] = @UserName, [Password] = @Password, [IsAdmin] = @IsAdmin WHERE [UserId] = @original_UserId AND [UserName] = @original_UserName AND [Password] = @original_Password AND [IsAdmin] = @original_IsAdmin"> |
| <DeleteParameters> |
| <asp:Parameter Name="original_UserId" Type="Int32" /> |
| <asp:Parameter Name="original_UserName" Type="String" /> |
| <asp:Parameter Name="original_Password" Type="String" /> |
| <asp:Parameter Name="original_IsAdmin" Type="String" /> |
| </DeleteParameters> |
| <UpdateParameters> |
| <asp:Parameter Name="UserName" Type="String" /> |
| <asp:Parameter Name="Password" Type="String" /> |
| <asp:Parameter Name="IsAdmin" Type="String" /> |
| <asp:Parameter Name="original_UserId" Type="Int32" /> |
| <asp:Parameter Name="original_UserName" Type="String" /> |
| <asp:Parameter Name="original_Password" Type="String" /> |
| <asp:Parameter Name="original_IsAdmin" Type="String" /> |
| </UpdateParameters> |
| <InsertParameters> |
| <asp:Parameter Name="UserName" Type="String" /> |
| <asp:Parameter Name="Password" Type="String" /> |
| <asp:Parameter Name="IsAdmin" Type="String" /> |
| </InsertParameters> |
| </asp:SqlDataSource> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| </td> |
| </tr> |
| </table> |
| </div> |
| </form> |
| </body> |
| </html> |