NeedDataSource called before ItemCommand

6 posts, 0 answers
  1. Sam
    Sam avatar
    6 posts
    Member since:
    Jul 2012

    Posted 20 Jul 2012 Link to this post

    Sir ,

    I am new for telerik. Am using the  hierarchical  radgrid. But causing error when enableviewstate=false.
    NeedDataSource called before ItemCommand.So my grid not able to fetch the proper data as its not gets the parentid in NeedDataSource.

    If enableviewstate=true my hierarchical  radgrid working fine but the parent columns header goes disappers.

    Am creating radgrid columns dynamically.

    The main thing is that am not getting my parent ticket it first as NeedDatasource calling first than itemdatacommand.


    Events are like this.

    initializParentGrid() 

     protected void radrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
          ;;;;;;;;;;;;
    bindGrid();
    }

     protected void radrid 
    _ItemCommand(object source, GridCommandEventArgs e)
        {

     if (e.CommandName == "ExpandCollapse")
            {
                GridTableView gtv = radrid 
    .MasterTableView.Items[e.Item.ItemIndex].ChildItem.NestedTableViews[0];
                Telerik.Web.UI.DataKey gdka = radrid 
            .MasterTableView.DataKeyValues[e.Item.ItemIndex];


                hdnDetailTableIndex.Value = e.Item.ItemIndex.ToString();


                if (gdka != null)
                    hdnParentTicketid.Value = gdka["ParentId"].ToString();


    }


    Please suggest.
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 22 Jul 2012 Link to this post

    Hello,

    enableviewstate=true is needed for fire itemcommand before needdatasource.

    Can you please provide more info about header disappear issue?

    Thanks,
    Jayesh Goyani
  3. Sam
    Sam avatar
    6 posts
    Member since:
    Jul 2012

    Posted 25 Jul 2012 Link to this post

    Sir,

    If enableviewstate=true my hierarchical  radgrid working fine but the parent columns header (Names) goes disappears.
    And the sorting by column name is not working.

    So is there any relation between them.

    Please guide.
  4. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 25 Jul 2012 Link to this post

    Hello,

    As per my knowledge there is not any relation between them.

    Can you please provide your grid's code, so we can try to resolved your issue?

    Thanks,
    Jayesh Goyani
  5. Sam
    Sam avatar
    6 posts
    Member since:
    Jul 2012

    Posted 25 Jul 2012 Link to this post

    Sir,

    Please check my following code.

    <telerik:RadGrid ID="gridShow" runat="server" SkinID="CR" EnableViewState="false"

                                        AutoGenerateColumns="false" PageSize="15" AllowPaging="True" AllowSorting="True"

                                        Width="99.2%" GridLines="None" OnNeedDataSource="gridShow_NeedDataSource" AllowCustomPaging="true"

                                        OnItemCommand="gridShow_ItemCommand" OnPreRender="gridShow_PreRender" OnLoad="gridShow_OnInit"

                                        OnItemDataBound="gridShow_ItemDataBound" AllowMultiRowSelection="false" OnSortCommand="gridShow_SortCommand">

                                        <MasterTableView DataKeyNames="ID,ParentId" HierarchyLoadMode="ServerOnDemand" ClientDataKeyNames="ID,TicketPriority,TicketStatus,ContactID"

                                            AllowCustomSorting="True" SkinID="CR"  EnableViewState="true" >

                                            <ParentTableRelation>

                                                <telerik:GridRelationFields DetailKeyField="ID" MasterKeyField="ParentId" />

                                            </ParentTableRelation>

                                            <DetailTables>

                                                <telerik:GridTableView AutoGenerateColumns="false" AllowPaging="false" AllowSorting="false"

                                                    EnableColumnsViewState="true" Width="100%" GridLines="None" SkinID="CRWidget"

                                                    ShowFooter="true" DataKeyNames="ID" ClientDataKeyNames="ID">

                                                </telerik:GridTableView>

                                            </DetailTables>

                                        </MasterTableView>

                                        <ItemStyle Wrap="False" />

                                        <HeaderStyle Wrap="False" />

                                        <PagerStyle AlwaysVisible="true" />

                                        <ClientSettings EnableRowHoverStyle="True" EnablePostBackOnRowClick="false">


    And Code bebind

    protected void gridShow _SortCommand(object source, GridSortCommandEventArgs e)

        {

            if (e.CommandArgument != "")

            {

                switch (e.OldSortOrder)

                {

                    case GridSortOrder.None:

                        OrderBy = e.CommandArgument + " ASC";

                        break;

                    case GridSortOrder.Ascending:

                        OrderBy = e.CommandArgument + " DESC";

                                          

                        break;

                    case GridSortOrder.Descending:

                        OrderBy = "";

                        break;

                }

                bindGrid();

            }

        }


  6. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 25 Jul 2012 Link to this post

    Hello,

    I have looked in your code i found there are some mistakes in it

    Correct code:
    EnableViewState="true"

    protected void gridShow _SortCommand(object source, GridSortCommandEventArgs e)
     
        {
     
         
    //below line not needed
    //            bindGrid();
     
             
     
        }

    Also check below link for reference
    http://demos.telerik.com/aspnet-ajax/grid/examples/programming/custompaging/defaultcs.aspx
    http://www.telerik.com/help/aspnet-ajax/grid-commands-that-invoke-rebind-implicitly.html

    Thanks,
    Jayesh Goyani
Back to Top