我正在使用Radgrid来管理会员资格 我想使用delete命令从数据库中删除一个用法, 但是当我点击删除按钮时,我不断收到此错误:
对象必须实现IConvertible。
奇怪的是删除机制有效;我的用户不再可用。 什么可能导致错误?
这是我的代码:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" AutoGenerateEditColumn="True" DataSourceID="SqlDataSource1" GroupPanelPosition="Top" Skin="Black"
AllowAutomaticUpdates="True" AllowAutomaticDeletes="True" AutoGenerateDeleteColumn="True" OnDeleteCommand="RadGrid1_DeleteCommand">
<MasterTableView AutoGenerateColumns="False" DataSourceID="SqlDataSource1" DataKeyNames="UserId">
<Columns>
<telerik:GridBoundColumn DataField="UserId" DataType="System.Guid" FilterControlAltText="Filter UserId column" HeaderText="UserId" ReadOnly="True" SortExpression="UserId" UniqueName="UserId" Visible="false">
</telerik:GridBoundColumn>
<telerik:GridCheckBoxColumn DataField="IsApproved" DataType="System.Boolean" FilterControlAltText="Filter IsApproved column" HeaderText="????? ?????" SortExpression="IsApproved" UniqueName="IsApproved">
</telerik:GridCheckBoxColumn>
<telerik:GridCheckBoxColumn DataField="IsLockedOut" DataType="System.Boolean" FilterControlAltText="Filter IsLockedOut column" HeaderText="IsLockedOut" SortExpression="IsLockedOut" UniqueName="IsLockedOut">
</telerik:GridCheckBoxColumn>
<telerik:GridBoundColumn DataField="UserName" FilterControlAltText="Filter UserName column" HeaderText="UserName" SortExpression="UserName" UniqueName="UserName">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Email" FilterControlAltText="Filter Email column" HeaderText="Email" SortExpression="Email" UniqueName="Email">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
在代码隐藏中:
protected void RadGrid1_DeleteCommand(object source, GridCommandEventArgs e)
{
try
{
GridDataItem dataItem = e.Item as GridDataItem;
string username = Convert.ToString(dataItem["UserName"].Text);
Label1.Text = "jkjh";
MembershipUser user = Membership.GetUser(username.ToString());
Membership.DeleteUser(user.UserName.ToString(),true);
}
...
}