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

Grid_Init Event Not Firing?

1 Answer 144 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lynn
Top achievements
Rank 2
Lynn asked on 05 Jan 2012, 09:44 PM
I am trying to modify the filter menus on the grid at runtime using an example directly from your onlne manual, but the Grid_Init event code in the server is not firing.

Can anyone tell me what I am doing wrong?

Here's the actual grid definition from the .aspx:

<telerik:RadGrid AutoGenerateColumns="false" ID="QualContsGrid" runat="server" Width="800px" OnItemCommand="QualContsGrid_ItemCommand"
    Height="430px" On
    AllowSorting="true" AllowFilteringByColumn="true" EnableLinqExpressions="true"
    OnItemDataBound="QualContsGrid_ItemDataBound"
    AllowPaging="true" PageSize="15"
    BorderWidth="1px" BorderColor="#999999" EnableEmbeddedSkins="true" Skin="Default"
    DataSourceID="SQLDataSource1"
    ShowFooter="True" GridLines="None" >
    <StatusBarSettings ReadyText="Ready" LoadingText="Loading..." />
    <MasterTableView >
        <Columns>
            <telerik:GridBoundColumn HeaderStyle-Width="125px" UniqueName="VoterFirstName" HeaderText="First Name" DataField="FirstName" SortExpression="FirstName" >
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderStyle-Width="125px" UniqueName="VoterLastName" HeaderText="Last Name" DataField="LastName" SortExpression="LastName" >
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn HeaderStyle-Width="300px" UniqueName="VoterAddress" HeaderText="Address" DataField="Address" SortExpression="Address" >
            </telerik:GridBoundColumn >
            <telerik:GridButtonColumn DataTextFormatString="Remove" ButtonType="PushButton" UniqueName="RemoveContribution" HeaderStyle-Width="75px"
                ConfirmText="Are you certain that you want to remove this contribution?"  Text="Remove"
                HeaderText="Remove" CommandName="RemoveContribution" CommandArgument="VoterQualifyingContributionId" DataTextField="VoterQualifyingContributionId" >
            </telerik:GridButtonColumn>
            <telerik:GridBoundColumn HeaderStyle-Width="125px" UniqueName="ContributionStatus" HeaderText="Status" DataField="PaymentDescription" SortExpression="PaymentDescription" >
            </telerik:GridBoundColumn >
            <telerik:GridBoundColumn UniqueName="VoterQualifyingContributionId" HeaderText="" DataField="VoterQualifyingContributionId" Visible="false" >
            </telerik:GridBoundColumn >
        </Columns>
    </MasterTableView>
    <ClientSettings>
        <Scrolling AllowScroll="true" UseStaticHeaders="true" />
    </ClientSettings>
</telerik:RadGrid>

The code behind contains:

protected void QualContsGrid_Init(object sender, System.EventArgs e)
{
    GridFilterMenu menu = QualContsGrid.FilterMenu;
    int i = 0;
    string a = "";
    while (i < menu.Items.Count)
    {
 
        a = menu.Items[i].Text;
 
        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);
        }
    }
}

The only reason the line of code "a = menu.Items[i].Text;" is in there is that I had a debug stop placed on it (and it never executed).  I also had a debug stop on the very first line in this event's code and it never fired.

On code/debug stops in Page_Init and Page_Load did fire correctly.

Also, code (and the debug stop) in the "QualContsGrid_AjaxRequest" DID execute correctly.

How do I get the RadGrid_Init event code to fire?

Thanks in advance!

Lynn

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 06 Jan 2012, 05:43 AM
Hello Lynn,

After inspecting your code, you have not attached the event oninit to your RadGrid. Here is the sample code
aspx:
<telerik:RadGrid ID="RadGrid1" runat="server" oninit="RadGrid1_Init" DataSourceID="SqlDataSource1" >
. . . .
</telerik:RadGrid>

-Shinu.
Tags
Grid
Asked by
Lynn
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Share this question
or