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

Update count of radiobutton checked within a radgrid

4 Answers 141 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Debojyoti
Top achievements
Rank 1
Debojyoti asked on 07 Jan 2011, 08:18 AM
I have a radgrid with 3 radiobutton in each row as a group. Either 1 will be selected and rest 2 will be not. My requirement is to show a count of radiobutton's selected for a particular page at the buttom of the grid(not footer). For eg. Not Mine:2, Remove:4, Keep: 4. The way that i thought of iterating through the MasterTable rows and get the radiobutton control but as it is in rad grid I cant get those. Please provide a solution.

Thanks in advance.

<telerik:RadGrid ID="grvReviewerView" runat="server" AutoGenerateColumns="False"
ShowFooter="true" GridLines="Both" EnableEmbeddedBaseStylesheet="true" EnableEmbeddedSkins="true"                                               AllowPaging="true" PageSize="10" AllowSorting="true" Skin="Office2007" OnDataBound="grvReviewerView_DataBound"                                                  OnNeedDataSource="grvReviewerView_NeedDataSource" AllowFilteringByColumn="true" ShowGroupPanel="True" EnableHeaderContextMenu="true" OnItemDataBound="grvReviewerView_ItemDataBound">                                                  <ClientSettings AllowColumnsReorder="true" ReorderColumnsOnClient="true" ColumnsReorderMethod="Reorder">
<Scrolling AllowScroll="true" UseStaticHeaders="true" EnableVirtualScrollPaging="true"                                                          FrozenColumnsCount="3" />
<ClientEvents OnRowClick="UpdateCount"/>
<Resizing AllowColumnResize="true" ResizeGridOnColumnResize="true" AllowResizeToFit="true" />
<Animation AllowColumnReorderAnimation="true" AllowColumnRevertAnimation="true" />
<Selecting UseClientSelectColumnOnly="true" />
  </ClientSettings>
  <PagerStyle AlwaysVisible="true" />
 <MasterTableView TableLayout="Fixed" AutoGenerateColumns="False" AllowMultiColumnSorting="true" GroupLoadMode="Client">
<Columns>
<telerik:GridTemplateColumn HeaderText="Not Mine" UniqueName="NotMine" AllowFiltering="false" HeaderStyle-Width="50px">
<ItemTemplate>
<asp:RadioButton ID="rdbNotMine" runat="server" GroupName="ReviewStatus" Checked='<%# Convert.ToBoolean(Eval("NotMine")) %>'/>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderStyle-Width="50px" HeaderText="Remove Access" UniqueName="RemoveAccess"
AllowFiltering="false">
<ItemTemplate>
<asp:RadioButton ID="rdbRemoveAccess" runat="server" GroupName="ReviewStatus" Checked='<%# Convert.ToBoolean(Eval("RemoveAccess")) %>'/>
</ItemTemplate>
</telerik:GridTemplateColumn>
 <telerik:GridTemplateColumn HeaderText="Keep Access" UniqueName="KeepAccess" AllowFiltering="false" HeaderStyle-Width="50px">
<ItemTemplate>
<asp:RadioButton ID="rdbKeepAccess" runat="server" GroupName="ReviewStatus" Checked='<%# Convert.ToBoolean(Eval("KeepAccess")) %>' />
</ItemTemplate>
</telerik:GridTemplateColumn>
<custom:CustomFilterClass DataField="Legacy_ID" FilterControlWidth="163px" HeaderText="User Legacy ID"
SortExpression="Legacy_ID">
<HeaderStyle Width="160px" />
<ItemTemplate>
<asp:Label ID="lblUserLegacyID" Text='<%# Eval("Legacy_ID") %>' runat="server"></asp:Label>
</ItemTemplate>
</custom:CustomFilterClass>
<custom:CustomFilterClass DataField="NT_Login" FilterControlWidth="163px" HeaderText="NT Name"
SortExpression="NT_Login">
<HeaderStyle Width="160px" />
<ItemTemplate>
<asp:Label ID="lblNTLogin" Text='<%# Eval("NT_Login") %>' runat="server"></asp:Label>
</ItemTemplate>
</custom:CustomFilterClass>
</Columns>
<AlternatingItemStyle />
<ItemStyle />
<HeaderStyle Wrap="false" />
<FooterStyle />
<NoRecordsTemplate>
 No Data
</NoRecordsTemplate>
</MasterTableView>
</telerik:RadGrid>

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 07 Jan 2011, 09:16 AM
Hello Debojyoti,

Check out the following code snippet which shows how to iterate through the grid and get the RadioButton.

C#:
foreach (GridDataItem item in RadGrid1.Items)//loops through each item
 {
  RadioButton radiobtn = (RadioButton)item.FindControl("rdbNotMine");//accessing RadioButton
  if (radiobtn.Checked)
       count++;
 }
 Label1.Text = "NotMine:" + count;//setting count to Label control which is outside RadGrid

Thanks,
Princy.
0
Debojyoti
Top achievements
Rank 1
answered on 07 Jan 2011, 09:35 AM
I want it to be done in Client side. Server side option can't be possible as there are huge amount of data and doing post back will take a lot of time.

I have written this function but this is not working. Giving error at the bold sections.while compiling. "The name 'rdbNotMine' does not exist in the current context" etc.

function UpdateCount(sender, eventArgs)
    {
        var grid = $find("<%=grvReviewerView.ClientID %>");
        alert("enter");
        var keepAcessCount,removeAcessCount,notMineCount = 0;
        var masterTable = grid.get_masterTableView();
        for(var i=0; i < masterTable.get_dataItems().length; i++)
        {
            var rdbNotMine1 = masterTable.get_dataItems()[i].$find('<%= rdbNotMine.ClientID%>');
            var rdbKeepAccess1 = masterTable.get_dataItems()[i].$find('<%= rdbKeepAccess.ClientID%>');
            var rdbRemoveAcess1 = masterTable.get_dataItems()[i].$find('<%= rdbRemoveAccess.ClientID%>');
            alert(rdbNotMine1);alert(rdbKeepAccess1);alert(rdbRemoveAcess1);
            if(rdbNotMine1.checked)
            {
                notMineCount = eval(notMineCount) + eval(1);
            }
            if(rdbKeepAccess1.checked)
            {
                keepAcessCount = eval(keepAcessCount) + eval(1);
            }
            if(rdbRemoveAcess1.checked)
            {   
                removeAcessCount = eval(removeAcessCount) + eval(1);
            }
        }
        document.getElementById('<%= lblKeepAccessCount.ClientID%>').innerHTML = keepAcessCount;    
        document.getElementById('<%= lblRemoveAccessCount.ClientID%>').innerHTML = removeAcessCount;    
        document.getElementById('<%= lblNotMineCount.ClientID%>').innerHTML = notMineCount;

    }
0
Accepted
Shinu
Top achievements
Rank 2
answered on 07 Jan 2011, 11:10 AM
Hello Debojyoti,

You could access the RadioButton by using the findElement method like below.

JavaScript:
function OnRowClick(sender, args)
    {
        var count = 0;
        var grid = $find("<%=RadGrid1.ClientID %>");
        var masterTable = grid.get_masterTableView();
        var items = masterTable.get_dataItems();
        for (var i = 0; i < masterTable.get_dataItems().length; i++)
         {
            var radiobtn = items[i].findElement("rdbNotMine");
            if (radiobtn.checked)
                count++;
        }
 
        var label1 = document.getElementById("lblNotMineCount");
        label1.innerText = count;
 }

Thanks,
Shinu.
0
Debojyoti
Top achievements
Rank 1
answered on 07 Jan 2011, 11:33 AM
Thanks a lot Shinu. It's perfect.
Tags
Grid
Asked by
Debojyoti
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Debojyoti
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or