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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
repeaterBind();
}
}
private void repeaterBind()
{
sqlRepeater.ConnectionString = ConfigurationManager.ConnectionStrings["sqlServer"].ConnectionString;
string req = "Select [libelle_fondamentaux] as libelle_fondamentaux, [id_categorie_fondamentaux] as id_categorie_fondamentaux from [BSC_Categorie_Fondamentaux] Order By [id_categorie_fondamentaux]";
sqlRepeater.SelectCommand = req;
RepeatFond.DataSource = null;
RepeatFond.DataBind();
}
public void RepeatFond_ItemDataBound(object Sender, RepeaterItemEventArgs e)
{
string toto = "";
// Si il s'agit d'un élément Item ou AlternatingItem.
if ((e.Item.ItemType == ListItemType.Item) | (e.Item.ItemType == ListItemType.AlternatingItem))
{
DropDownList ddl = (DropDownList)e.Item.FindControl("ddl_avancement");
// Tu récupère la valeur sélectionnée (le texte ou la valeur associée)
// ddl.SelectedItem.Text
// ou ddl.SelectedItem.Value
if (ddl != null && ddl.SelectedItem != null)
toto = ddl.SelectedItem.Value;
// Récupération id de la categ.
int idFond = int.Parse(((DataRowView)e.Item.DataItem)["id_categorie_fondamentaux"].ToString());
// Stock le GridView1 dans une variable
GridView myGridView = (GridView)e.Item.FindControl("GridViewFond");
// Construction du GridView
myGridView.DataSource = dsListeFondamentaux(idFond);
myGridView.DataBind();
}
}
private DataSet dsListeFondamentaux(int idFond)
{
// Création d'une instance de connexion
SqlConnection oConnexion = new SqlConnection();
oConnexion.ConnectionString = ConfigurationManager.ConnectionStrings["sqlServer"].ConnectionString;
// Création d'un DataSet
DataSet myDataset = new DataSet();
SqlDataAdapter dtr = new SqlDataAdapter("Select [BSC_Fondamentaux].[id_fondamentaux] as id_fondamentaux, [BSC_Fondamentaux].[libelle_fondamentaux] as fondamentaux, [BSC_Type_Validation].[libelle_validation] as validation, [BSC_Type_Validation].[id_type_validation] as idvalidation from [BSC_Fondamentaux], [BSC_Etat_Fondamentaux], [BSC_Type_Validation], [BSC_Categorie_Fondamentaux] Where [BSC_Etat_Fondamentaux].[id_type_validation]=[BSC_Type_Validation].[id_type_validation] And [BSC_Etat_Fondamentaux].[id_fondamentaux]=[BSC_Fondamentaux].[id_fondamentaux] And [BSC_Fondamentaux].[id_categorie_fondamentaux]=[BSC_Categorie_Fondamentaux].[id_categorie_fondamentaux] And [BSC_Categorie_Fondamentaux].[id_categorie_fondamentaux] = '" + idFond + "' Order By [BSC_Fondamentaux].[id_fondamentaux]", oConnexion);
dtr.Fill(myDataset);
// Retourne le DataSet
return myDataset;
}
public void ddl_change(object source, RepeaterCommandEventArgs e)
{
string status;
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DropDownList ddl = (DropDownList)e.Item.FindControl("ddl_avancement");
// Tu récupère la valeur sélectionnée (le texte ou la valeur associée)
if (ddl != null && ddl.SelectedItem != null)
status = ddl.SelectedItem.Text;
// Faire des traitements avec la variable récupérée
}
foreach (RepeaterItem Item in RepeatFond.Items)
{
if (((DropDownList)Item.FindControl("ddl_avancement")).Text != "")
{
// traitement
}
}
} |
Partager