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

NeedDataSource called before ItemCommand

5 Answers 135 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sam
Top achievements
Rank 1
Sam asked on 20 Jul 2012, 02:30 PM
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.

5 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 22 Jul 2012, 07:08 PM
Hello,

enableviewstate=true is needed for fire itemcommand before needdatasource.

Can you please provide more info about header disappear issue?

Thanks,
Jayesh Goyani
0
Sam
Top achievements
Rank 1
answered on 25 Jul 2012, 06:14 AM
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.
0
Jayesh Goyani
Top achievements
Rank 2
answered on 25 Jul 2012, 06:52 AM
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
0
Sam
Top achievements
Rank 1
answered on 25 Jul 2012, 07:35 AM
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();

        }

    }


0
Jayesh Goyani
Top achievements
Rank 2
answered on 25 Jul 2012, 09:53 AM
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
Tags
General Discussions
Asked by
Sam
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Sam
Top achievements
Rank 1
Share this question
or