Mar 18, 2010, 11:55 AM
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
and this is my ashx code
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
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