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

GridTemplateColumn Checkbox Issue

2 Answers 101 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Darren
Top achievements
Rank 1
Darren asked on 26 Aug 2010, 05:37 PM

I have a grid where you select the grid item via a checkbox inside a templatecolumn, when you click on the checkbox it highlights the grid item and then i do other operations on the grid selected items.

The problem is that when you click one row via the checkbox other functionality does not work after that intial click, for example if i wanted to select another row via the checkbox it will not highlight the row and partial postback does not occur, i can resolve the issue by turning off ajax.

So basically you click any checkbox in any row and then functions do not work for instance the authorise command does not work, it is like the page invalid.

Attached grid html:

<telerik:RadGrid 
    ID="paymentsGrid" 
    runat="server"
    AllowSorting="False" 
    AllowPaging="False"
    AllowFilteringByColumn="False"
    AllowAutomaticInserts="True"
    AllowAutomaticUpdates="True"
    AllowAutomaticDeletes="True" 
    AutoGenerateColumns="False"
    MasterTableView-HeaderStyle-Wrap="false"
    MasterTableView-ItemStyle-Wrap="false" 
    GridLines="None" 
    ShowFooter="true"
    EnableLinqExpressions="false"
    onitemdatabound="paymentsGrid_ItemDataBound"
    OnItemCommand="paymentsGrid_OnItemCommand"
    ShowHeader="true"
    AllowMultiRowSelection="true">
      
    <MasterTableView CommandItemDisplay="Top">
      
     <CommandItemTemplate>
         <div style="margin:5px;padding:5px">
            <div style="float:right">
            <asp:LinkButton ID="lbAuthorise" runat="server" CommandName="Authorise" OnClientClick="javascript:if(!confirm('Are you sure you want to authorise the selected payments?')){return false;}">Authorise</asp:LinkButton>
            </div>
        </div>
  
         </CommandItemTemplate>  
           
        <RowIndicatorColumn>
            <HeaderStyle Width="20px"></HeaderStyle>
        </RowIndicatorColumn>
  
        <ExpandCollapseColumn>
            <HeaderStyle Width="20px"></HeaderStyle>
        </ExpandCollapseColumn>
          
        <Columns>
          
            <telerik:GridBoundColumn DataField="PeriodFrom" ReadOnly="true" UniqueName="PeriodFrom" HeaderText="From" DataFormatString="{0:dd/MM/yyyy}"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="PeriodTo" ReadOnly="true" UniqueName="PeriodTo" HeaderText="To" DataFormatString="{0:dd/MM/yyyy}"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ContractReference" ReadOnly="true" UniqueName="ContractReference" HeaderText="CT-No"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ContractName" ReadOnly="true" UniqueName="ContractName" HeaderText="Contract"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="SiteName" ReadOnly="true" UniqueName="SiteName" HeaderText="Site"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="TotalCost" ReadOnly="true" UniqueName="TotalCost" HeaderText="Cost" Aggregate="Sum" DataFormatString="{0:C2}" FooterAggregateFormatString="Total: {0:C2}"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="AuthorisedBy" ReadOnly="true" UniqueName="AuthorisedBy" HeaderText="Authorised By"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="AuthorisedWhen" ReadOnly="true" UniqueName="AuthorisedWhen" HeaderText="Authorised When"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="AuthorisedAmount" ReadOnly="true" UniqueName="AuthorisedAmount" HeaderText="Authorised Amount" Aggregate="Sum" DataFormatString="{0:C2}" FooterAggregateFormatString="Total Authorised: {0:C2}"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="SiteID" ReadOnly="true" Display="false" UniqueName="SiteID"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ContractID" ReadOnly="true" Display="false" UniqueName="ContractID"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="PaymentID" ReadOnly="true" Display="false" UniqueName="PaymentID"></telerik:GridBoundColumn>
             
            <telerik:GridTemplateColumn UniqueName="selectionColumn" AllowFiltering="false" HeaderStyle-Width="27px">
            <HeaderTemplate>
            <asp:CheckBox id="chkPaymentGridHeader" OnCheckedChanged="paymentsGrid_HeaderCheckChanged" AutoPostBack="True" runat="server"></asp:CheckBox>
            </HeaderTemplate>
            <ItemTemplate>
            <asp:CheckBox id="chkPaymentGridItem" OnCheckedChanged="paymentsGrid_ItemCheckChanged" AutoPostBack="True" runat="server"></asp:CheckBox>
            </ItemTemplate>
            </telerik:GridTemplateColumn
                      
        </Columns>
          
        <ItemStyle Wrap="False"></ItemStyle>
        <HeaderStyle Wrap="False"></HeaderStyle>
        <FooterStyle Wrap="false"></FooterStyle>
      
    </MasterTableView>
  
    
</telerik:RadGrid>


The checkbox events:
protected void paymentsGrid_HeaderCheckChanged(object sender, EventArgs e)
         {
             if ((sender as CheckBox).Checked)
             {
                 foreach (GridDataItem dataItem in paymentsGrid.MasterTableView.Items)
                 {
                     (dataItem.FindControl("chkPaymentGridItem") as CheckBox).Checked = true;
                     dataItem.Selected = true;
                 }
             }
             else
             {
                 foreach (GridDataItem dataItem in paymentsGrid.MasterTableView.Items)
                 {
                     (dataItem.FindControl("chkPaymentGridItem") as CheckBox).Checked = false;
                     dataItem.Selected = false;
                 }
             }
         }
  
         protected void paymentsGrid_ItemCheckChanged(object sender, EventArgs e)
         {
             bool itemIsChecked = (sender as CheckBox).Checked;
  
             ((sender as CheckBox).Parent.Parent as GridItem).Selected = (sender as CheckBox).Checked;
  
         }


iam using version q1 2010

Thanks

2 Answers, 1 is accepted

Sort by
0
Darren
Top achievements
Rank 1
answered on 26 Aug 2010, 05:45 PM
Forgto to mention that this code works fine running from visual studio, it is once it is deployed to sharepoint 2007 that it has this ajax issue
0
Darren
Top achievements
Rank 1
answered on 27 Aug 2010, 09:37 AM
Solved the issue

It was a rogue piece of javascript that sharepoint did not like.
Tags
Grid
Asked by
Darren
Top achievements
Rank 1
Answers by
Darren
Top achievements
Rank 1
Share this question
or