This is a migrated thread and some comments may be shown as answers.

[Solved] RadGrid with item template checkbox

1 Answer 383 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sneha Gokarn
Top achievements
Rank 1
Sneha Gokarn asked on 11 Dec 2009, 12:47 PM
I want to apply role management in a grid
I have 3 tables in the database 1. Role master 2.Action Master 3.RoleActionAssociation
the procedure is
@RoleID int
as
select actionname,isnull(ra.actionid,0) from actionmaster
left outer join
(select actionid from roleactionassociation where roleid=@RoleID
) ra
on (actionmaster.actionid=ra.actionid)

now this gets me all the names of the actions present alongside the actionids
if the role is associated then the actionid is displayed else its null

Now I want to display this in the grid ie if the actionid is null I need the checkbox to be checked else unchecked
Rad Grid is as follows
<telerik:RadGrid   AutoGenerateDeleteColumn="true"    ID="RolesActionsGrid" runat="server" AutoGenerateColumns="False" AllowAutomaticInserts="false"
    AllowAutomaticDeletes="false"  AllowPaging="true" allowSorting="true">
<MasterTableView>
<Columns>
<telerik:GridBoundColumn DataField="ActionName" HeaderText="Permissions" SortExpression="ActionName">


</telerik:GridBoundColumn>
<telerik:GridBoundColumn  DataField="ActionID" Visible="false" HeaderText="Permissions" SortExpression="ActionID">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn>
<HeaderTemplate>
<asp:CheckBox  runat="server" id="checkAll"/>
</HeaderTemplate>
<ItemTemplate >
<asp:CheckBox id="checkIndividual" runat="server" />
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>

code behind

 Protected Sub DDRoles_SelectedIndexChanged(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs) Handles DDRoles.SelectedIndexChanged

        Dim objActions As New clsActionMaster
        Dim objDataTable As New DataTable

        objDataTable = objActions.getActionsByRoleID(15).Tables(0)
        RolesActionsGrid.DataSource = objDataTable
        RolesActionsGrid.DataBind()

    End Sub


    Protected Sub RolesActionsGrid_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles RolesActionsGrid.DataBound
        For Each item As GridDataItem In RolesActionsGrid.Items


        Next



    End Sub

Even when I check uncheck the checkbox an appropriate function shld be called





1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 16 Dec 2009, 12:04 PM
Hello Sneha,

For the checked status of the checkbox, you can use a code block, to evaluate whether it should be checked or not. This may look something like:

<telerik:GridTemplateColumn>
<HeaderTemplate>
<asp:CheckBox runat="server" ID="checkAll" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="checkIndividual" runat="server" Checked='<%# (Container as GridDataItem)["CategoryID"].Text=="1" %>' />
</ItemTemplate>
</telerik:GridTemplateColumn>

Additionally, you can allow the header checkbox to postback on a check, to alter the state of all the checkboxes in the column.
I hope this information helps.

Sincerely yours,

Yavor
the Telerik team

 


Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Sneha Gokarn
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or