Pass id Master GridPanel to detail GridPanel when I add new Detail element

  1. #1

    Pass id Master GridPanel to detail GridPanel when I add new Detail element

    Hi,I've two grid, one is the Master and the other is the Details of the Master's element selected.
    when I add a new element in Details table, I must pass a Master ID to the Stored Procedure, and I don't know how todo.


    This is my aspx code




    this is my code behind


    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Xml.Linq;
    using Coolite.Ext.Web;
    
    
    namespace Survey.Survey.Admin
    {
        public partial class SurveySpecialFieldsNew : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                Permissions.checkPermissionAdmin();
    
    
                if (!Ext.IsAjaxRequest)
                {
                    _dataBind();
                }
            }
    
    
            protected void sSurveySpecialFields_RefreshData(object sender, StoreRefreshDataEventArgs e)
            {
                _dataBind();
            }
    
    
            private void _dataBind()
            {
                sSurveySpecialFields.DataSource = SurveyEngine.DataAccess.SurveySpecialField.List();
                sSurveySpecialFields.DataBind();
            }
    
    
            protected void commandClick(object sender, AjaxEventArgs e)
            {
                string idSurveySpecialField = e.ExtraParams["key"];
                if (!string.IsNullOrEmpty(idSurveySpecialField))
                {
                    switch (e.ExtraParams["Command"])
                    {
                        case "Delete":
                            Ext.Msg.Confirm("Eliminazione Campo Speciale", "Sei sicuro di voler eliminare il campo speciale e tutti i suoi dettagli?", new MessageBox.ButtonsConfig
                            {
                                Yes = new MessageBox.ButtonConfig
                                {
                                    Handler = "Coolite.AjaxMethods.DoYes(" + idSurveySpecialField + ")",
                                    Text = "Si"
                                },
                                No = new MessageBox.ButtonConfig
                                {
                                    Handler = "",
                                    Text = "No"
                                }
                            }).Show();
    
    
                            break;
                    }
                }
            }
    
    
            [AjaxMethod]
            public void DoYes(string idSurveySpecialField)
            {
                SurveyEngine.DataAccess.SurveySpecialField.Delete(Convert.ToInt32(idSurveySpecialField));
                //TODO: Non sono riuscito a trovare il modo di far aggiornare la griglia. Ho fatto una mascabanata facendo un redirect
                //su se stessa, ma c'è l'effetto brutto del postback
                Response.Redirect("SurveySpecialFieldsNew.aspx");
            }
    
    
            protected void sSurveySpecialFieldDetails_RefreshData(object sender, StoreRefreshDataEventArgs e)
            {
                pnlSurveySpecialFieldDetails.Hidden = false;
                string id = e.Parameters["IDSpecialField"];
                _dataBindDetails(Convert.ToInt32(id));
            }
    
    
            private void _dataBindDetails(int idSpecialField)
            {
                sSurveySpecialFieldDetails.DataSource = SurveyEngine.DataAccess.SurveySpecialFieldDetails.List(idSpecialField);
                sSurveySpecialFieldDetails.DataBind();
            }
    
    
            protected void commandClickDetail(object sender, AjaxEventArgs e)
            {
                string idSurveySpecialFieldDetail = e.ExtraParams["key"];
                if (!string.IsNullOrEmpty(idSurveySpecialFieldDetail))
                {
                    switch (e.ExtraParams["Command"])
                    {
                        case "Delete":
                            Ext.Msg.Confirm("Eliminazione Dettaglio", "Sei sicuro di voler eliminare il dettaglio?", new MessageBox.ButtonsConfig
                            {
                                Yes = new MessageBox.ButtonConfig
                                {
                                    Handler = "Coolite.AjaxMethods.DoYesDetail(" + idSurveySpecialFieldDetail + ")",
                                    Text = "Si"
                                },
                                No = new MessageBox.ButtonConfig
                                {
                                    Handler = "",
                                    Text = "No"
                                }
                            }).Show();
    
    
                            break;
                    }
                }
            }
    
    
            [AjaxMethod]
            public void DoYesDetail(string idSurveySpecialFieldDetail)
            {
                SurveyEngine.DataAccess.SurveySpecialFieldDetails.Delete(Convert.ToInt32(idSurveySpecialFieldDetail));
                //TODO: Non sono riuscito a trovare il modo di far aggiornare la griglia. Ho fatto una mascabanata facendo un redirect
                //su se stessa, ma c'è l'effetto brutto del postback
                Response.Redirect("SurveySpecialFieldsNew.aspx");
            }
        }
    }

    and this is my ashx code


    using System;
    using System.Collections;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    using System.Xml.Linq;
    
    
    using Coolite.Ext.Web;
    using SurveyEngine.Survey;
    
    
    namespace Survey.Shared
    {
        /// <summary>
        /// Summary description for $codebehindclassname$
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        public class SurveySpecialFieldDetailsSave : IHttpHandler
        {
    
    
            public void ProcessRequest(HttpContext context)
            {
                Response sr = new Response(true);
    
    
                try
                {
                    StoreDataHandler dataHandler = new StoreDataHandler(context);
                    ChangeRecords<SurveySpecialFieldDetail> data = dataHandler.ObjectData<SurveySpecialFieldDetail>();
    
    
                    foreach (SurveySpecialFieldDetail specialFieldDetail in data.Updated)
                    {
                        //Modifica il record
                        SurveyEngine.DataAccess.SurveySpecialFieldDetails.Update(
                        specialFieldDetail.IDSpecialFieldDetail,
                        specialFieldDetail.Description,
                        specialFieldDetail.Active
                        ) ;
                    }
    
    
                    foreach (SurveySpecialFieldDetail specialFieldDetail in data.Created)
                    {
                        //TODO: non sono stato in grado di far passare l'ID del padre della riga selezionata a questa classe
                        //ho dovuto estrarre nel dettaglio l'id del padre x ogni riga
                        SurveyEngine.DataAccess.SurveySpecialFieldDetails.Insert(
                         specialFieldDetail.IDSpecialField, //THIS IS THE PROBLEM
                         specialFieldDetail.Description,
                         specialFieldDetail.Active
                         ) ;
                    }
                }
                catch (Exception e)
                {
                    sr.Success = false;
                    sr.Msg = e.Message;
                }
    
    
                sr.Write();
            }
    
    
            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
    }


    any idea?




    the second problem is when I delete a row, I show a alert, I click "yes" button and for refresh my grid I must todo a redirect to mypage self.....


    the first question is very import; this second is less important.


    thank's
  2. #2

    RE: Pass id Master GridPanel to detail GridPanel when I add new Detail element

    I've solved the first problem with the code "WriteBaseParam" in a Store object.

    see the code:


    
    
    <ext:Store ID="sSurveySpecialFieldDetails" runat="server" OnRefreshData="sSurveySpecialFieldDetails_RefreshData" 
    	    DirtyWarningText="Non hai salvato le informazioni modificate. Sei sicuro di voler ricaricare i dati senza salvarli?" DirtyWarningTitle="Attenzione!">
    	    <UpdateProxy>
                <ext:HttpWriteProxy Method="POST" Url="../../Shared/SurveySpecialFieldDetailsSave.ashx" />
            </UpdateProxy>
            <Reader>
                <ext:JsonReader ReaderID="IDSpecialFieldDetail">
                    <Fields>
                        <ext:RecordField Name="IDSpecialFieldDetail" Type="Int" />
                        <ext:RecordField Name="Description" />
                        <ext:RecordField Name="Active" Type="Boolean" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
            <BaseParams>
                <ext:Parameter 
                    Name="IDSpecialField" 
                    Value="#{gpSurveySpecialFields}.getSelectionModel().hasSelection() ? #{gpSurveySpecialFields}.getSelectionModel().getSelected().id : -1"
                    Mode="Raw" />
            </BaseParams>
            <WriteBaseParams>
    			<ext:Parameter 
                    Name="IDSpecialField2" 
                    Value="#{gpSurveySpecialFields}.getSelectionModel().hasSelection() ? #{gpSurveySpecialFields}.getSelectionModel().getSelected().id : -1"
                    Mode="Raw" />
            </WriteBaseParams>
            <Listeners>
    			<BeforeSave Handler="#{sSurveySpecialFieldDetails}" />
                <LoadException Handler="Ext.Msg.alert('Dettaglio Campo Speciale - Caricamento fallito', e.message || e )" />
                <CommitFailed Handler="Ext.Msg.alert('Dettaglio Campo Speciale - Approvazione fallita', 'Errore: ' + msg)" />
                <Save Handler="Ext.Msg.alert('Salvataggio','Salvataggio completato con successo');" />
                <SaveException Handler="Ext.Msg.alert('Dettaglio Campo Speciale - Salvataggio fallito', e.message || e)" />
                <CommitDone Handler="Ext.Msg.alert('Dettaglio Campo Speciale - Approvato', 'I dati sono stati correttamente salvati');" />
            </Listeners>
        </ext:Store>

    in this mode, the param is passed in my ashx page and I capture the value with code
    Convert.ToInt32(context.Request.Params["IDSpecialField2"])



    however I've not solved the problem when I delete a row in gridpanel: unique mode for reload the page is the redirect ?????


    thanks

  3. #3

    awesome man, you solved my problem

    Hi,
    I am a newbie to this ex.net myselves.
    And was spending lot of time trying to figure this out.
    But this post of yours helped me.

    In case you are interested, I can share my last problem and the solution with code.

    Regards
    Khush

    Quote Originally Posted by John Writers View Post
    I've solved the first problem with the code "WriteBaseParam" in a Store object.

    see the code:


    
    
    <ext:Store ID="sSurveySpecialFieldDetails" runat="server" OnRefreshData="sSurveySpecialFieldDetails_RefreshData" 
    	    DirtyWarningText="Non hai salvato le informazioni modificate. Sei sicuro di voler ricaricare i dati senza salvarli?" DirtyWarningTitle="Attenzione!">
    	    <UpdateProxy>
                <ext:HttpWriteProxy Method="POST" Url="../../Shared/SurveySpecialFieldDetailsSave.ashx" />
            </UpdateProxy>
            <Reader>
                <ext:JsonReader ReaderID="IDSpecialFieldDetail">
                    <Fields>
                        <ext:RecordField Name="IDSpecialFieldDetail" Type="Int" />
                        <ext:RecordField Name="Description" />
                        <ext:RecordField Name="Active" Type="Boolean" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
            <BaseParams>
                <ext:Parameter 
                    Name="IDSpecialField" 
                    Value="#{gpSurveySpecialFields}.getSelectionModel().hasSelection() ? #{gpSurveySpecialFields}.getSelectionModel().getSelected().id : -1"
                    Mode="Raw" />
            </BaseParams>
            <WriteBaseParams>
    			<ext:Parameter 
                    Name="IDSpecialField2" 
                    Value="#{gpSurveySpecialFields}.getSelectionModel().hasSelection() ? #{gpSurveySpecialFields}.getSelectionModel().getSelected().id : -1"
                    Mode="Raw" />
            </WriteBaseParams>
            <Listeners>
    			<BeforeSave Handler="#{sSurveySpecialFieldDetails}" />
                <LoadException Handler="Ext.Msg.alert('Dettaglio Campo Speciale - Caricamento fallito', e.message || e )" />
                <CommitFailed Handler="Ext.Msg.alert('Dettaglio Campo Speciale - Approvazione fallita', 'Errore: ' + msg)" />
                <Save Handler="Ext.Msg.alert('Salvataggio','Salvataggio completato con successo');" />
                <SaveException Handler="Ext.Msg.alert('Dettaglio Campo Speciale - Salvataggio fallito', e.message || e)" />
                <CommitDone Handler="Ext.Msg.alert('Dettaglio Campo Speciale - Approvato', 'I dati sono stati correttamente salvati');" />
            </Listeners>
        </ext:Store>

    in this mode, the param is passed in my ashx page and I capture the value with code
    Convert.ToInt32(context.Request.Params["IDSpecialField2"])



    however I've not solved the problem when I delete a row in gridpanel: unique mode for reload the page is the redirect ?????


    thanks

Similar Threads

  1. Finish master-detail
    By andrefreitasjr in forum 1.x Help
    Replies: 2
    Last Post: Dec 02, 2011, 12:06 AM
  2. Edit master detail with LinqDataSource
    By andrefreitasjr in forum 1.x Help
    Replies: 1
    Last Post: Dec 01, 2011, 8:16 PM
  3. Replies: 1
    Last Post: Jun 01, 2011, 3:22 PM
  4. Master/Detail and reusable content
    By clovisrossi in forum Open Discussions
    Replies: 0
    Last Post: May 24, 2010, 2:35 PM
  5. Looking For Master Detail Form example
    By kumarxlnt in forum Examples and Extras
    Replies: 1
    Last Post: Nov 01, 2009, 5:17 PM

Posting Permissions