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

Modifying Grid Filter Menu Causes Loop

3 Answers 101 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lynn
Top achievements
Rank 2
Lynn asked on 14 Feb 2012, 06:00 PM
I am trying to modify the filter menus in a grid.  I have done this before (successfully), so I copied the event code from the other web page that was working fine, pasted it into a second .aspx, and everytime it executes it goes into a CPU loop -- which I cannot locate the source of using normal debugging techniques.

I have attached a screen capture of the grid at run-time so you can visualize it.

The source code for the actual grid is immediately below, and the related event code which is causing the problem is included below that.  If I comment out the event code, the page runs fine.  If I let the While..Loop execute, a cpu-loop will result without any debug stops being executed.

Any help would be most appreciated!  It will probably turn out to be something stupid I am doing, but for the life of me, I cannot find it.

Thanks for any assistance in advance!

Lynn

<telerik:RadGrid ID="gvCCECCommitteeProperties" GridLines="None" AutoGenerateColumns="false" PageSize="15" EnableEmbeddedSkins="true" Skin="Default"
    Width="99%" AllowFilteringByColumn="true" AllowAutomaticDeletes="false" AllowMultiRowEdit="false" AllowMultiRowSelection="false"
    AllowPaging="true" AllowSorting="false" runat="server" OnItemCreated="gvCCECCommitteeProperties_ItemCreated"
    DataSourceID="SqlDataSource1" AllowAutomaticUpdates="true" AllowAutomaticInserts="False"
    OnInit="gvCCECCommitteeProperties_Init"
    SelectCommandType="StoredProcedure" SelectCommand="SelectEmployees"
    UpdateCommandType=""
    UpdateCommand="UPDATE [CCECCommitteeProperties] SET [LastName] = @LastName, [FirstName] = @FirstName, [MiddleName] = @MiddleName, [Suffix] = @Suffix, [IsDependent] = @IsIndependent, [IsUnopposed] = @IsUnapplosed, [IsOneParty] = @IsOneParty, [IsPrimaryWinner] = @IsPrimaryWinner, [IsGeneralWinner] = @IsGeneralWinner, [IsActive] = @IsActive, [IsQualifiedForBallot] = @IsQualifiedForBallot, [IsReallocated] = @IsReAllocated, [IsIncumbent] = @IsIncumbent WHERE [CCECCommitteePropertyID] = @CCECCommitteePropertyID"
    ShowStatusBar="true">
    <MasterTableView ShowFooter="false" DataKeyNames="CCECCommitteePropertyID" EditMode="InPlace" CommandItemDisplay="TopAndBottom">
        <Columns>
            <telerik:GridEditCommandColumn FooterText="EditCommand footer" UniqueName="EditCommandColumn"
                HeaderText="Edit" HeaderStyle-Width="100px" UpdateText="Update">
            </telerik:GridEditCommandColumn>
 
            <telerik:GridTemplateColumn HeaderStyle-Width="250px" HeaderText="Names<br>(Last Name)" AllowFiltering="true" DataField="LastName">
                <ItemTemplate>
                    <div style="width: 250px">
                        <asp:Label Width="100px" ID="Label1" runat="server" Text="Last Name;" ></asp:Label>  <asp:Label Width="100px" ID="txtLastName" runat="server" Text='<%# Bind("LastName") %>'></asp:Label>
                        <br />
                        <asp:Label Width="100px" ID="Label2" runat="server" Text="First Name:" ></asp:Label>  <asp:Label Width="100px" ID="txtFirstName" runat="server" Text='<%# Bind("FirstName") %>'></asp:Label>
                        <br />
                        <asp:Label Width="100px" ID="Label4" runat="server" Text="Middle Name:" ></asp:Label>  <asp:Label Width="100px" ID="txtMiddleName" runat="server" Text='<%# Bind("MiddleName") %>'></asp:Label>
                        <br />
                        <asp:Label Width="100px" ID="Label3" runat="server" Text="Suffix:" ></asp:Label>  <asp:Label Width="100px" ID="txtSuffix" runat="server" Text='<%# Bind("Suffix") %>'></asp:Label>
                    </div>
                </ItemTemplate>
                <EditItemTemplate>
                    <div style="width: 250px" >
                        <asp:Label Width="100px" ID="Label1" runat="server" Text="Last Name;" ></asp:Label>  <asp:TextBox Width="100px" ID="LastName" runat="server" Text='<%# Bind("LastName") %>'></asp:TextBox>
                        <br />
                        <asp:Label Width="100px" ID="Label2" runat="server" Text="First Name:" ></asp:Label>  <asp:TextBox Width="100px" ID="FirstName" runat="server" Text='<%# Bind("FirstName") %>'></asp:TextBox>
                        <br />
                        <asp:Label Width="100px" ID="Label4" runat="server" Text="Middle Name:" ></asp:Label>  <asp:TextBox Width="100px" ID="MiddleName" runat="server" Text='<%# Bind("MiddleName") %>'></asp:TextBox>
                        <br />
                        <asp:Label Width="100px" ID="Label3" runat="server" Text="Suffix:" ></asp:Label>  <asp:TextBox Width="100px" ID="Suffix" runat="server" Text='<%# Bind("Suffix") %>'></asp:TextBox>
                    </div>
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
 
 
            <telerik:GridTemplateColumn HeaderText="Information<br>(Filer Id)" AllowFiltering="true" DataField="CommitteeID">
                <ItemTemplate>
                    <div style="float: left;">
                    FilerID:  <asp:Label ID="lblFilerID" runat="server" Text='<%# Eval("CommitteeID") %>'></asp:Label>
                        <br />
                    Party:  <asp:Label ID="lblCandidateParty" runat="server" Font-Bold="False" Text='<%# Eval("PartyName") %>'></asp:Label>
                    </div>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridCheckBoxColumn AllowFiltering="true" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" DataField="IsActive" HeaderText="Active?" ></telerik:GridCheckBoxColumn>
            <telerik:GridCheckBoxColumn AllowFiltering="true" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" DataField="IsIndependent" HeaderText="Independent?" ></telerik:GridCheckBoxColumn>
 
            <telerik:GridCheckBoxColumn AllowFiltering="true" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" DataField="IsUnopposed" HeaderText="Unopposed?" ></telerik:GridCheckBoxColumn>
            <telerik:GridCheckBoxColumn AllowFiltering="true" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" DataField="IsOneParty" HeaderText="One Party<br>Dominant?" ></telerik:GridCheckBoxColumn>
            <telerik:GridCheckBoxColumn AllowFiltering="true" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" DataField="IsPrimaryWinner" HeaderText="Primary<br>Winner?" ></telerik:GridCheckBoxColumn>
 
            <telerik:GridCheckBoxColumn AllowFiltering="true" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" DataField="IsGeneralWinner" HeaderText="General<br>Winner?" ></telerik:GridCheckBoxColumn>
            <telerik:GridCheckBoxColumn AllowFiltering="true" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" DataField="IsQualifiedForBallot" HeaderText="Qualified<br>for Ballot?" ></telerik:GridCheckBoxColumn>
 
            <telerik:GridCheckBoxColumn AllowFiltering="true" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" DataField="IsReallocated" HeaderText="Reallocated?" ></telerik:GridCheckBoxColumn>
            <telerik:GridCheckBoxColumn AllowFiltering="true" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" DataField="IsIncumbent" HeaderText="Incumbent?" ></telerik:GridCheckBoxColumn>
 
            <telerik:GridBoundColumn Visible="false" DataField="OfficeID" ></telerik:GridBoundColumn>
 
        </Columns>
    </MasterTableView>
</telerik:RadGrid>


Now the relevant event code:

protected void gvCCECCommitteeProperties_Init(object sender, System.EventArgs e)
{
    GridFilterMenu menu = gvCCECCommitteeProperties.FilterMenu;
    int i = 0;
 
    while (i < menu.Items.Count)
    {
        if (i == 0)
        {
            if (menu.Items[i].Text == "NoFilter" || menu.Items[i].Text == "Contains" || menu.Items[i].Text == "StartsWith" || menu.Items[i].Text == "EqualTo")
            {
                i++;
            }
            else
            {
                menu.Items.RemoveAt(i);
            }
        }
    }
}

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 15 Feb 2012, 05:01 AM
Hello Lynn,

After inspecting your code, I suppose the loop occurs because of the if condition(if(i==0)) you have used inside  the while loop. Try removing the if condition and check whether it makes any difference.

-Shinu.
0
Lynn
Top achievements
Rank 2
answered on 22 Feb 2012, 07:00 PM
Actually, the loop was occurring sometime early in the page construction before any control was ever passed to my code.  I had "debug stops" at the start of every single event and nothing was ever executed.  I have since moved on to other matters, but this one may come back later.  You may close it, but I cannot mark your response as an answer.

Lynn
0
Casey
Top achievements
Rank 1
answered on 22 Feb 2012, 08:12 PM
Hi Lynn,

I know you said that you are on to other matters, but it looks like the loop occurs after "i" is incremented. It will stay in the loop because you have i < menu.Items.Count, and then if (i ==0). Since "i" is 1 at that time, it doesn't increment it again, and it will continually loop since "i" always stays at 1. Could you try removing the "if(i ==0)" to see if it works as expected then?

I hope this helps!
Casey

while (i < menu.Items.Count)
{
    if (menu.Items[i].Text == "NoFilter" || menu.Items[i].Text == "Contains" || menu.Items[i].Text == "StartsWith" || menu.Items[i].Text == "EqualTo")
        {
            i++;
        }
        else
        {
            menu.Items.RemoveAt(i);
        }
}
Tags
Grid
Asked by
Lynn
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Lynn
Top achievements
Rank 2
Casey
Top achievements
Rank 1
Share this question
or