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

[Solved] GridButtonColumn and DataBind = suppress event

3 Answers 194 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Michele
Top achievements
Rank 2
Michele asked on 25 Feb 2010, 04:42 PM
Hello,
I'm get stucked with the ajax application I'm developing... I've got a master table with a detail table, the detail table shows the groups a user is binded to and I've got a button for removing the user from group... the problem is that the DataBind in the page load suppresses the gvUtenti_ItemCommand...

Here're my ASPX :

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GestioneUtenti.aspx.cs" 
    EnableEventValidation="true" Inherits="IFWebLight.Web.Management.Content.GestioneUtenti" %> 
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
<head runat="server"
    <title></title
</head> 
<body> 
    <form id="form1" runat="server" style="height: auto; width: auto"
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server"
    </telerik:RadScriptManager> 
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" /> 
    <telerik:RadAjaxManager runat="server" ID="radAjax" DefaultLoadingPanelID="RadAjaxLoadingPanel1"
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="gvUtenti"
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="gvUtenti" /> 
                    <telerik:AjaxUpdatedControl ControlID="gvGruppoUtenti" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
            <telerik:AjaxSetting AjaxControlID="gvGruppoUtenti"
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="gvGruppoUtenti" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManager> 
    <telerik:RadScriptBlock runat="server" ID="scriptBlock"
 
        <script type="text/javascript"
                <!-- 
            function onRowDropping(sender, args) { 
                if (sender.get_id() == "<%=gvUtenti.ClientID %>") { 
                    var node = args.get_destinationHtmlElement(); 
                    if (!isChildOf('<%=gvGruppoUtenti.ClientID %>', node) && !isChildOf('<%=gvUtenti.ClientID %>', node)) { 
                        args.set_cancel(true); 
                    } 
                } 
                else { 
                    var node = args.get_destinationHtmlElement(); 
                    if (!isChildOf('trashCan', node)) { 
                        args.set_cancel(true); 
                    } 
                    else { 
                        if (confirm("Are you sure you want to delete this order?")) 
                            args.set_destinationHtmlElement($get('trashCan')); 
                        else 
                            args.set_cancel(true); 
                    } 
                } 
            } 
 
            function isChildOf(parentId, element) { 
                while (element) { 
                    if (element.id && element.id.indexOf(parentId) > -1) { 
                        return true; 
                    } 
                    elementelement = element.parentNode; 
                } 
                return false; 
            } 
 
            function LoadUtentiGrid(sender) { 
                alert(sender); 
            } 
 
 
           
             --> 
        </script> 
 
    </telerik:RadScriptBlock> 
    <div> 
        <div style="width: 49%; float: left"
            <telerik:RadGrid ID="gvUtenti" runat="server" BackColor="LightSteelBlue" AllowFilteringByColumn="True" OnItemCommand="gvUtenti_ItemCommand" 
                AutoGenerateColumns="False" GridLines="None" ShowGroupPanel="True" AllowPaging="True" OnPageIndexChanged="RadGrid1_PageIndexChanged" 
                AllowMultiRowSelection="true" AllowSorting="True" OnRowDrop="gvUtenti_Drop" OnDetailTableDataBind="gvUtenti_DetailDataBind"
                <MasterTableView GroupLoadMode="Client" ClientDataKeyNames="Codice" > 
                    <ExpandCollapseColumn Visible="True"
                    </ExpandCollapseColumn> 
                    <Columns> 
                        <telerik:GridBoundColumn HeaderText="Codice" HeaderButtonType="TextButton" DataField="Codice"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn HeaderText="Descrizione" HeaderButtonType="TextButton" DataField="Descrizione"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn HeaderText="PWD" HeaderButtonType="TextButton" DataField="PWD"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn HeaderText="Filiale" HeaderButtonType="TextButton" DataField="Filiale"
                        </telerik:GridBoundColumn> 
                    </Columns> 
                    <DetailTables   > 
                        <telerik:GridTableView Name="gvGruppi" > 
                            <Columns> 
                                <telerik:GridBoundColumn HeaderText="Gruppo" HeaderButtonType="TextButton" DataField="DescrizioneGruppo"
                                </telerik:GridBoundColumn> 
                                      <telerik:GridButtonColumn ButtonType="PushButton" Text="prova" CommandName="CancellaGruppo" > 
                             
                            </telerik:GridButtonColumn> 
                            </Columns> 
                        </telerik:GridTableView> 
                    </DetailTables> 
                </MasterTableView> 
                 
                <ClientSettings AllowRowsDragDrop="true"
                    <Selecting AllowRowSelect="True" EnableDragToSelectRows="false" /> 
                    <ClientEvents OnRowDropping="onRowDropping" /> 
                </ClientSettings> 
            </telerik:RadGrid> 
        </div> 
        <div style="width: 50%; float: right"
            <div> 
                <asp:Label Text="Gruppi" runat="server"></asp:Label> 
                <telerik:RadComboBox ID="cbGruppi" runat="server" Width="250px" Height="150px" EmptyMessage="Selezionare un gruppo" 
                    EnableLoadOnDemand="true" ShowMoreResultsBox="false" AutoPostBack="true" EnableVirtualScrolling="false" 
                    OnSelectedIndexChanged="cbGruppi_IndexChanged"
                    <WebServiceSettings Method="GetGruppi" Path="../WS/IFManagement.svc" /> 
                </telerik:RadComboBox> 
            </div> 
            <div style="height: 400px"
                <telerik:RadGrid ID="gvGruppoUtenti"  runat="server" 
                    BackColor="LightSteelBlue" AutoGenerateColumns="False" ShowGroupPanel="True" 
                    AllowPaging="True" AllowMultiRowSelection="true" AllowSorting="True"
                    <MasterTableView>  <%--OnDeleteCommand="OnGridCancel"--%> 
                        <ExpandCollapseColumn Visible="True"
                        </ExpandCollapseColumn> 
                        <Columns> 
                            <telerik:GridBoundColumn HeaderText="Utente" DataField="User"
                            </telerik:GridBoundColumn> 
                            <telerik:GridBoundColumn HeaderText="Descrizione" HeaderButtonType="TextButton" DataField="Descrizione"
                            </telerik:GridBoundColumn> 
                            <telerik:GridButtonColumn ButtonType="PushButton" Text="prova" CommandName="Delete" CommandArgument="A"
                             
                            </telerik:GridButtonColumn> 
 
                        </Columns> 
                    </MasterTableView> 
                    <ClientSettings AllowRowsDragDrop="true"
                        <%-- <DataBinding SelectMethod="GetDataAndCount" Location="../WS/IFManagement.svc" 
                        SortParameterType="Linq"  FilterParameterType="Linq"></DataBinding> 
                         <ClientEvents OnCommand="pLoad()" />--%> 
                    </ClientSettings> 
                </telerik:RadGrid> 
            </div> 
        </div> 
    </div> 
 
    <script language="javascript" type="text/javascript"
           <!-- 
        function pLoad() { 
 
            var dataSource = null
 
            var tableView = $find('gvGruppoUtenti').get_masterTableView(); 
 
            if (tableView.get_dataItems().length == 0) { 
                alert('ok'); 
                $find('gvGruppoUtenti').get_masterTableView().set_dataSource(dataSource); 
                $find('gvGruppoUtenti').get_masterTableView().dataBind(); 
            } 
            else { 
                alert('dati'); 
            } 
 
        }  
              
             --> 
    </script> 
 
    </form> 
</body> 
</html> 
 

and my .Cs (important parts) file

    private IFManagement clientManagement; 
        private List<UtenteGruppo> m_ListaUtenteGruppo; 
        private List<Utente> m_ListaUtente; 
        private int idxPage; 
 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            clientManagement = new IFManagement(); 
 
            if (IsPostBack) 
            { 
                if (Cache["lug"] != null) 
                { 
                    m_ListaUtenteGruppo = (List<UtenteGruppo>)Cache["lug"]; 
 
                    gvGruppoUtenti.DataSource = m_ListaUtenteGruppo
                    gvGruppoUtenti.DataBind(); 
                } 
                if (Cache["lu"] != null) 
                { 
                    m_ListaUtente = (List<Utente>)Cache["lu"]; 
 
                    gvUtenti.DataSource = m_ListaUtente
                    gvUtenti.DataBind(); //(*)
                } 
                
            } 
            else 
                LoadUtenti(); 
        } 
 
 
 private void LoadUtenti() 
        { 
            if (m_ListaUtente == null) 
            { 
                m_ListaUtente = clientManagement.GetListaUtenti(); 
                Cache["lu"] = m_ListaUtente; 
            } 
 
            gvUtenti.DataSource = m_ListaUtente
            gvUtenti.DataBind(); 
 
            Cache["a"] = gvUtenti; 
 
            gvGruppoUtenti.MasterTableView.EnableNoRecordsTemplate = true
            gvGruppoUtenti.MasterTableView.NoDetailRecordsText = "vuoto"
 
        } 
 
 
 protected void gvUtenti_DetailDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e) 
        { 
            GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem; 
            Utente u = dataItem.DataItem as Utente; 
 
            if (null != u) 
            { 
                e.DetailTableView.DataSource = u.GruppiAppartenenza; 
            } 
            else 
                e.DetailTableView.DataSource = null
        } 
 
 
 protected void gvUtenti_ItemCommand(object source, GridCommandEventArgs e) 
        { 
            if (e.CommandName == "CancellaGruppo") 
            { 
                int iRewardID = 0
 
            } 
 
        } 

If I do the (*) in pageload the gvUtenti_ItemCommand will be suppressed... what am I doing wrong? I was so happy of having moved to SL and not having to do anymore with postbacks...but past returns!
Thanks

Paolo


3 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 26 Feb 2010, 07:33 AM
Hello Paolo,

You should be using Advanced data-binding in your scenario as opposed to Simple data-binding.

I hope this helps. 

Regards,
Tsvetoslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Michele
Top achievements
Rank 2
answered on 26 Feb 2010, 08:52 AM
Hello Tsvetoslav,
I've tried your approach but got some problem with the detail view...
It ask for data, I've seen it in



protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            int i = 0;
            if(!e.IsFromDetailTable) // <- here is true if detail
               LoadUtenti();
        }

But how Do I got the MasterTable selected row (and possibily the DataItem associated with it?)
Thanks

Paolo
0
Tsvetoslav
Telerik team
answered on 03 Mar 2010, 04:38 PM
Hello Paolo,

You need to use the DetailTableDataBind  event and get the master-table item as follows:

protected void RadGrid1_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e)
{
    GridDataItem item = e.DetailTableView.ParentItem;
}

Best wishes,
Tsvetoslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Ajax
Asked by
Michele
Top achievements
Rank 2
Answers by
Tsvetoslav
Telerik team
Michele
Top achievements
Rank 2
Share this question
or