Bonjour,

J'ai crée un UserConrol possedant une gridview. Ne souhaitant pas utiliser de SQLDATASOURCE j'ai decidé de remplir
cette gridview dans le code behind à l'aide de la méthodes databind, datasource, LINQ. Ensuite j'utilise les méthodes suivantes afin d'éditer cette
meme gridview à l'aide de procédures stockées : rowCancelingEdit_Click, rowUpdating_Click, rowEditing_Click.
Jusque ici tout va bien lorsque j'ajoute mon userControl dans une page test.aspx celui-ci fonctionne parfaitement.

Par contre quand j'ajoute mon usercontrol dans une autre page beaucoup plus complexe (multiview/view/ajax), ma gridview
ne fonctionne plus en mode edition.Ce sont les postbacks qui posent problémes car je les gères dans mon usercontrol afin
d'update une row ainsi que dans la page appelant le userControl : Lorsque je passe en mode edition la
gridview disparait. Voici le code du userControl :

J'ai entendu parler des viewstates mais comment les utiliser avec une gridview dans mon cas.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
 
[Category("Configuration")]
public String recordId { get; set; }
 
protected void Page_Load(object sender, EventArgs e)
{
	if(!IsPostBack)
		PopulateGridview();
} 
 
private void PopulateGridview()
{
	this.GridView_Cashflow.DataSource = CashflowRow.getCashflowRowbyRecordId(recordId);
	this.GridView_Cashflow.DataBind();
}
 
protected void rowEditing_Click(object sender, GridViewEditEventArgs e)
{
	GridView_Cashflow.EditIndex = e.NewEditIndex;
	PopulateGridview();
}
 
protected void rowCancelingEdit_Click(object sender, GridViewCancelEditEventArgs e)
{
	GridView_Cashflow.EditIndex = -1;
	PopulateGridview();
}
 
protected void rowUpdating_Click(object sender, GridViewUpdateEventArgs e)
{
	tbl_dealmaker_CashflowRow _cshf = new tbl_dealmaker_CashflowRow();
 
	_cshf.CashflowRowID = (int)GridView_Cashflow.DataKeys[e.RowIndex].Value;
 
	_cshf.Year1 = Convert.ToInt32(((GridView_Cashflow.Rows[e.RowIndex].FindControl("txt_year1") as TextBox).Text));
	_cshf.Year2 = Convert.ToInt32(((GridView_Cashflow.Rows[e.RowIndex].FindControl("txt_year2") as TextBox).Text));
	_cshf.Year3 = Convert.ToInt32(((GridView_Cashflow.Rows[e.RowIndex].FindControl("txt_year3") as TextBox).Text));
	_cshf.Year4 = Convert.ToInt32(((GridView_Cashflow.Rows[e.RowIndex].FindControl("txt_year4") as TextBox).Text));
	_cshf.Year5 = Convert.ToInt32(((GridView_Cashflow.Rows[e.RowIndex].FindControl("txt_year5") as TextBox).Text));
	_cshf.Year6 = Convert.ToInt32(((GridView_Cashflow.Rows[e.RowIndex].FindControl("txt_year6") as TextBox).Text));
	_cshf.Year7 = Convert.ToInt32(((GridView_Cashflow.Rows[e.RowIndex].FindControl("txt_year7") as TextBox).Text));
 
	CashflowRow.updateCashflowByCashflowRowId(_cshf);
 
	GridView_Cashflow.EditIndex = -1;
 
	PopulateGridview();
}