Hi, i have a check box to edit normal or admin user, I'd like to turn this checkbox visible to False if the User to be edited is the same logged. this is the code I have.
Resumed code
<MasterTableView AutoGenerateColumns="false" EditMode="EditForms" CommandItemDisplay="Top" DataKeyNames="name, admin ">
<Columns>
<telerik:GridBoundColumn UniqueName="name" DataField="name" meta:resourceKey="name"/>
<telerik:GridCheckBoxColumn UniqueName="admin" DataField="admin" DefaultInsertValue="False" DataType="System.Boolean" meta:resourceKey="Admin"/>
<telerik:GridEditCommandColumn HeaderStyle-Width="100px" meta:resourceKey="EditLnk"/>
<telerik:GridButtonColumn CommandName="Acervos" UniqueName="AcervosColumn" HeaderStyle-Width="100px" meta:resourceKey="AcervosLnk" />
<telerik:GridButtonColumn CommandName="Delete" UniqueName="DeleteColumn" HeaderStyle-Width="100px" meta:resourceKey="DeleteLnk"/>
</Columns>
<SortExpressions>
<telerik:GridSortExpression FieldName="name" SortOrder="Ascending" />
</SortExpressions>
<EditFormSettings EditFormType="Template" >
<FormTemplate >
<div style="width: 300px" >
<div style="margin:5px;">
<asp:Label ID="NameLbl" runat="server" meta:resourceKey="NameLbl"/> <asp:TextBox ID="NameTxt" runat="server" Text='<%# Bind("name") %>'/>
</div>
<div style="margin:5px;">
<asp:Label ID="PassLbl" runat="server" meta:resourceKey="PassLbl"/> <asp:TextBox ID="PassTxt" runat="server" Text='<%# Bind("pass") %>' TextMode="Password" />
</div>
<div style="margin:5px;">
<asp:CheckBox ID="AdminChk" runat="server" meta:resourceKey="AdminChk" Checked='<%# Bind("admin") %>' /> </div>
<div style="margin:10px;text-align:right;">
<telerik:RadButton ID="btnUpdate" Text='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), AddJS, UpdateJS) %>' runat="server" CommandName='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "PerformInsert", "Update")%>'/>
<telerik:RadButton ID="btnCancel" runat="server" CausesValidation="False" CommandName="Cancel" meta:resourceKey="CancelBtn" />
</div>
</div>
</FormTemplate>
</EditFormSettings>
</MasterTableView>
Code Behind
Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand
If e.CommandName = RadGrid.EditCommandName Then
Dim Usuario As String = HttpContext.Current.User.Identity.Name.ToLower
If Usuario = e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("name").ToString().ToLower Then
Dim editItem As GridEditFormItem = CType(e.Item, GridEditFormItem)
Dim ChkBxItem As CheckBox = CType(editItem.FindControl("AdminChk"), CheckBox)
ChkBxItem.Checked = False
End If
End If
Every time I run, it shows a message! Can not convert an object of type 'Telerik.Web.UI.GridDataItem' in type 'Telerik.Web.UI.GridEditFormItem'.
How can I solve this?
Resumed code
<MasterTableView AutoGenerateColumns="false" EditMode="EditForms" CommandItemDisplay="Top" DataKeyNames="name, admin ">
<Columns>
<telerik:GridBoundColumn UniqueName="name" DataField="name" meta:resourceKey="name"/>
<telerik:GridCheckBoxColumn UniqueName="admin" DataField="admin" DefaultInsertValue="False" DataType="System.Boolean" meta:resourceKey="Admin"/>
<telerik:GridEditCommandColumn HeaderStyle-Width="100px" meta:resourceKey="EditLnk"/>
<telerik:GridButtonColumn CommandName="Acervos" UniqueName="AcervosColumn" HeaderStyle-Width="100px" meta:resourceKey="AcervosLnk" />
<telerik:GridButtonColumn CommandName="Delete" UniqueName="DeleteColumn" HeaderStyle-Width="100px" meta:resourceKey="DeleteLnk"/>
</Columns>
<SortExpressions>
<telerik:GridSortExpression FieldName="name" SortOrder="Ascending" />
</SortExpressions>
<EditFormSettings EditFormType="Template" >
<FormTemplate >
<div style="width: 300px" >
<div style="margin:5px;">
<asp:Label ID="NameLbl" runat="server" meta:resourceKey="NameLbl"/> <asp:TextBox ID="NameTxt" runat="server" Text='<%# Bind("name") %>'/>
</div>
<div style="margin:5px;">
<asp:Label ID="PassLbl" runat="server" meta:resourceKey="PassLbl"/> <asp:TextBox ID="PassTxt" runat="server" Text='<%# Bind("pass") %>' TextMode="Password" />
</div>
<div style="margin:5px;">
<asp:CheckBox ID="AdminChk" runat="server" meta:resourceKey="AdminChk" Checked='<%# Bind("admin") %>' /> </div>
<div style="margin:10px;text-align:right;">
<telerik:RadButton ID="btnUpdate" Text='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), AddJS, UpdateJS) %>' runat="server" CommandName='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "PerformInsert", "Update")%>'/>
<telerik:RadButton ID="btnCancel" runat="server" CausesValidation="False" CommandName="Cancel" meta:resourceKey="CancelBtn" />
</div>
</div>
</FormTemplate>
</EditFormSettings>
</MasterTableView>
Code Behind
Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand
If e.CommandName = RadGrid.EditCommandName Then
Dim Usuario As String = HttpContext.Current.User.Identity.Name.ToLower
If Usuario = e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("name").ToString().ToLower Then
Dim editItem As GridEditFormItem = CType(e.Item, GridEditFormItem)
Dim ChkBxItem As CheckBox = CType(editItem.FindControl("AdminChk"), CheckBox)
ChkBxItem.Checked = False
End If
End If
Every time I run, it shows a message! Can not convert an object of type 'Telerik.Web.UI.GridDataItem' in type 'Telerik.Web.UI.GridEditFormItem'.
How can I solve this?