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

Grid Controls Lose Data On Postback

1 Answer 129 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dave Myers
Top achievements
Rank 1
Dave Myers asked on 22 Oct 2010, 04:01 PM
I am under the gun here and having a weird issue with RadGrid.  I am using regular data bind (datasource = , databind()).  The grid has some template columns that contain a textbox and a slider.  Whenever I got to capture the values of the slider or the textbox on a postback...both return empty.  Any ideas on what could be causing this?  One note is that not all the rows are displayed upon loading of the grid and I dynamically show them.  Here is the page:
<%@ Register Src="~/BusinessModules/Report/EarnedValueReportSection.ascx" TagName="EarnedValueReportSection" TagPrefix="uc1" %>
<%@ Control Language="vb" AutoEventWireup="false" Inherits="Digisoft.DS.UI.Web.ProgramEarnedValueControl" CodeFile="ProgramEarnedValueControl.ascx.vb" %>
<script type="text/javascript">
    //variables
    var gridProject;
    var tableProject;
     
    //itit Functions
    function initProjectGrid(sender,args){
        //set gridProject,tableProject
        gridProject = sender;
        tableProject = gridProject.get_masterTableView();
    }
     
    function toggleTreeRows(gridId,rowId,storageId,buttonName) {
        var rows = tableProject.get_dataItems();
        var row;
        var childRow;
        var rowVisible = false;
        var childOpen = false;
        var parentLineage = '';
        var childLineage = '';
        var parentLevel = 0;
        var childLevel = 0;
        var storageList = '';
        var storageCtl = document.getElementById(storageId);
        var openCloseCtl;
         
        for (var i = 0; i < rows.length; i++){
            row = rows[i];
            openCloseCtl = row.findElement(buttonName);
            if (parentLineage != '') {
                childLineage = row.get_element().getAttribute('lineage');
                   
                if (childLineage.indexOf(parentLineage) == 0) {
                    childLevel = childLineage.split('/').length;
                    if (childLevel == (parentLevel + 1)){
                        if (childOpen == 'true'){
                            //hide child
                            row.get_element().setAttribute('open','false');
                            if (openCloseCtl.getAttribute("onclick") != null) {
                                openCloseCtl.setAttribute('src',openCloseCtl.getAttribute('src').replace('minus','plus'));
                            }
                            tableProject.hideItem(i);
                        }
                        else {
                            //show child
                            row.get_element().setAttribute('open','true');
                            if (openCloseCtl.getAttribute("onclick") != null) {
                                openCloseCtl.setAttribute('src',openCloseCtl.getAttribute('src').replace('minus','plus'));
                            }
                            tableProject.showItem(i);
                        }
                    }
                    else {
                        //hide non-first level children
                        row.get_element().setAttribute('open','false');
                        if (openCloseCtl.getAttribute("onclick") != null) {
                            openCloseCtl.setAttribute('src',openCloseCtl.getAttribute('src').replace('plus','minus'));
                        }
                        tableProject.hideItem(i);
                    }
                }
            }
            if (rowId == row.get_element().getAttribute('lineage')){
                parentLineage = row.get_element().getAttribute('lineage');
                parentLevel = parentLineage.split('/').length;
                childOpen = tableProject.get_dataItems()[i + 1].get_element().getAttribute('open');
                if (childOpen == 'true'){
                    openCloseCtl.setAttribute('src',openCloseCtl.getAttribute('src').replace('minus','plus'));
                }
                else {
                    openCloseCtl.setAttribute('src',openCloseCtl.getAttribute('src').replace('plus','minus'));
                }
            }
            if (row.get_element().getAttribute('open') == 'true') {
                storageList += row.get_element().getAttribute('lineage') + ','
            }
        }
        storageCtl.value = storageList;
    }
     
    function onSliderValueChange(sender, args){
        var sliderPercentText;
         
        sliderPercentText = document.getElementById(sender.get_element().getAttribute('sliderPercentTxtId'));
        sliderPercentText.value = sender.get_value();
    }
     
    function onSliderEnd(sender, args){
        var valueArray;
        var sliderPercentText;
        var valueParent;
        var valueChild;
        var weightChild;
        var percentChild;
        var rows;
        var row;
        var rowParent;
        var slider;
        var sliderParent;
        var projectId;
        var projectParentId = '';
        var sliderName;
        var hasChildren;
         
        sliderName = sender.get_element().getAttribute('sliderName');
        rows = tableProject.get_dataItems();
         
        valueArray = new Array(rows.length - 1);
         
        //set the values for projects that do not have children in preparation for rolling up.
        for (var i = 0; i <= rows.length - 1; i++){
            row = rows[i];
            slider = row.findControl(sliderName);
            hasChildren = slider.get_element().getAttribute('sliderHasChildren');
            percentChild = slider.get_value();
            if (hasChildren == 'false'){
                valueArray[i] = (percentChild / 100);
            }
            else {
                valueArray[i] = 0;
            }
        }
         
        //roll up values
        for (var i = rows.length - 1; i >= 0; i--){
            row = rows[i];
            slider = row.findControl(sliderName);
            projectParentId = slider.get_element().getAttribute('sliderProjectParentId');
            percentChild = valueArray[i];
            weightChild = slider.get_element().getAttribute('sliderWeight');
             
            if (i !== 0){
                for (var x = (i - 1); x >= 0; x--){
                    rowParent = rows[x];
                    sliderParent = rowParent.findControl(sliderName);
                    projectId = sliderParent.get_element().getAttribute('sliderProjectId');
                     
                    if (projectId == projectParentId) {
                        valueArray[x] += (valueArray[i] * weightChild);
                        break;
                    }
                }
            }
        }
         
        //set value for projects that have children
        for (var i = 0; i < rows.length - 1; i++){
            row = rows[i];
            slider = row.findControl(sliderName);
            hasChildren = slider.get_element().getAttribute('sliderHasChildren');
            sliderPercentText = document.getElementById(slider.get_element().getAttribute('sliderPercentTxtId'));
            valueArray[i] = (valueArray[i] * 100);
            if (hasChildren == 'true'){
                slider.set_value(valueArray[i].toFixed(0));
                sliderPercentText.value = valueArray[i].toFixed(0);
            }
        }
    }
</script>
<style type="text/css" media="all">
    input.label {
        width: 200px;
        border: none;
        color: #000000;
        background-color: transparent;
        text-align: right;
    }
</style>
<asp:updatepanel id="DisplayPanel" Visible="False" UpdateMode="Always" Runat="server">
    <Triggers>
        <asp:PostBackTrigger ControlID="CloseBtn" />
    </Triggers>
    <ContentTemplate>
        <des:DSUpdateProgress ID="UpdateProgress1" AssociatedUpdatePanelID="DisplayPanel" runat="server">
            <ProgressTemplate>
                <div class="ProgressPanel">
                      
                </div>
                <div class="InnerProgressPanel">
                    <img src="images/ajax-loader.gif" alt="Loading..." /> Loading...
                </div>
            </ProgressTemplate>
        </des:DSUpdateProgress>
        <table width="100%" cellpadding="0" cellspacing="0">
            <tr>
                <td align="center" class="DisplayPanel">
                    <telerik:RadSplitter ID="MainSplitter" runat="server" Height="540" Width="100%">
                        <telerik:RadPane ID="ProjectsPane" Scrolling="Both" Width="25%" PersistScrollPosition="true" runat="server">
                            <asp:HiddenField ID="ProjectTreeHolder" runat="server" />
                            <telerik:RadGrid ID="ProjectGrid" runat="server">
                                <ClientSettings >
                                    <Selecting AllowRowSelect="true" />
                                    <Scrolling AllowScroll="false" />
                                </ClientSettings>
                                <MasterTableView Width="100%" AutoGenerateColumns="false" ClientDataKeyNames="Level,BaseID,StateMode" DataKeyNames="ID" HeaderStyle-Wrap="false">
                                    <Columns>
                                        <telerik:GridTemplateColumn HeaderText=" " UniqueName="ProjectColumn" ItemStyle-Wrap="false">
                                            <ItemTemplate>
                                                <input type="hidden" id="ID" runat="server" value='<%# DataBinder.Eval(Container,"DataItem.ID")%>' />
                                                <input type="hidden" id="ParentID" runat="server" value='<%# DataBinder.Eval(Container,"DataItem.ParentID")%>' />
                                                <input type="hidden" id="Level" runat="server" value='<%# DataBinder.Eval(Container,"DataItem.Level")%>' />
                                                <input type="hidden" id="Lineage" runat="server" value='<%# DataBinder.Eval(Container,"DataItem.Lineage")%>' />
                                                <input type="hidden" id="HasChildren" runat="server" value='<%# DataBinder.Eval(Container,"DataItem.HasChildren")%>' />
                                                <span style="text-decoration:none;"><%#DataBinder.Eval(Container, "DataItem.Padding")%></span>
                                                <asp:Image ID="ProjectOpenCloseImg" runat="server" />
                                                <des:DisableLinkButton ID="ProjectSelectBtn" OnCommand="ProjectSelectBtn_OnCommand" Text='<%# DataBinder.Eval(Container,"DataItem.NameLong")%>' CommandArgument='<%# DataBinder.Eval(Container,"DataItem.ID")%>' CausesValidation="true" runat="server"></des:DisableLinkButton>
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridBoundColumn HeaderText="Manager" DataField="Manager.DisplayName" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left"></telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn HeaderText="Start Date" DataFormatString="{0:d}" DataField="StartDate" HeaderStyle-HorizontalAlign="Center"  ItemStyle-HorizontalAlign="Center"></telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn HeaderText="End Date" DataFormatString="{0:d}" DataField="EndDate" HeaderStyle-HorizontalAlign="Center"  ItemStyle-HorizontalAlign="Center"></telerik:GridBoundColumn>
                                        <telerik:GridTemplateColumn HeaderText="Active" ItemStyle-Wrap="false" ItemStyle-HorizontalAlign="center">
                                            <ItemTemplate>
                                                <asp:Image runat="server" Visible='<%# DataBinder.Eval(Container,"DataItem.IsActive")%>' ID="IsActiveImg" ImageUrl="~/images/check.gif" />
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridTemplateColumn HeaderText="Child Weight" UniqueName="ChildWeight" ItemStyle-Wrap="false"  HeaderStyle-HorizontalAlign="Center"  ItemStyle-HorizontalAlign="Center">
                                            <ItemTemplate>
                                                <asp:Label ID="ChildWeightLbl" runat="server"></asp:Label>%
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridTemplateColumn HeaderText="Previous %" UniqueName="PreviousPercent" ItemStyle-Wrap="false"  HeaderStyle-HorizontalAlign="Center"  ItemStyle-HorizontalAlign="Center">
                                            <ItemTemplate>
                                                <asp:Label ID="PercentPreviousLbl" runat="server"></asp:Label>%
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridTemplateColumn HeaderText="%" UniqueName="Percent" ItemStyle-Wrap="false"  HeaderStyle-HorizontalAlign="Center"  ItemStyle-HorizontalAlign="Center">
                                            <ItemTemplate>
                                                <asp:TextBox ID="PercentTxt" CssClass="label" Width="30px" runat="server"></asp:TextBox>%
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridTemplateColumn HeaderText=" " UniqueName="PercentSlider" ItemStyle-Wrap="false" HeaderStyle-Width="5px">
                                            <ItemTemplate>
                                                <telerik:RadSlider ID="PercentSlider" runat="server"></telerik:RadSlider>
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridBoundColumn HeaderText="Budget" DataFormatString="{0:c}" DataField="CalculatedBudgetTotalCost" HeaderStyle-HorizontalAlign="Center"  ItemStyle-HorizontalAlign="Center"></telerik:GridBoundColumn>
                                    </Columns>
                                </MasterTableView>
                            </telerik:RadGrid>
                        </telerik:RadPane>
                        <telerik:RadSplitBar ID="MainSplitBar" CollapseMode="None" EnableResize="True" runat="server" />
                        <telerik:RadPane ID="DetailsPane" Scrolling="Both" Width="75%" PersistScrollPosition="true" runat="server">
                            <uc1:EarnedValueReportSection ID="EarnedValueReportSec" runat="server" />
                        </telerik:RadPane>
                    </telerik:RadSplitter>
                </td>
            </tr>
            <tr>
                <td class="TabDisplayFooter" align="right">
                    <des:disablelinkbutton id="CloseBtn" runat="server" enabledcssclass="CommandButton" disabledcssclass="DisabledCommandButton" Visible="True"></des:disablelinkbutton>
                </td>
            </tr>
        </table>
    </ContentTemplate>
</asp:updatepanel>

I would have preferred to just get the value of the slider instead of having to put the value in the textbox....

1 Answer, 1 is accepted

Sort by
0
Dave Myers
Top achievements
Rank 1
answered on 22 Oct 2010, 05:38 PM
Never mind....I guess the long hours are getting to me.  Problem was that the grid was being re-bound before any data was captured....doh!
Tags
Grid
Asked by
Dave Myers
Top achievements
Rank 1
Answers by
Dave Myers
Top achievements
Rank 1
Share this question
or