using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; namespace WebApplication1 { public class Livre { public Livre(bool isDotnet, string name) { this.isDotnet = isDotnet; this.name = name; } public bool isDotnet { get; set; } public string name { get; set; } } public partial class _Default : System.Web.UI.Page { private List<Livre> bibliotheque = new List<Livre>(); protected void Page_Load(object sender, EventArgs e) { Label1.Text = " Livres sélectionnés : "; if (!IsPostBack) { LoadData(); } } public void LoadData() { bibliotheque.Add(new Livre(true, @"c# par la pratique")); bibliotheque.Add(new Livre(false, @"Linux for dummies")); Repeater1.DataSource = from l in bibliotheque select l; Repeater1.DataBind(); } public void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType ListItemType.Item || e.Item.ItemType ListItemType.AlternatingItem) { Livre livre = (Livre) e.Item.DataItem ; CheckBox chkIsDotnet = e.Item.FindControl("chkIsDotnet") as CheckBox; chkIsDotnet.Checked = livre.isDotnet; TextBox txtName = e.Item.FindControl("txtName") as TextBox; txtName.Text = livre.name; } } protected void Button1_Click(object sender, EventArgs e) { foreach (RepeaterItem item in Repeater1.Items) { if ((item.FindControl("chkIsDotnet")as CheckBox).Checked) { Label1.Text = String.Concat(Label1.Text,(item.FindControl("txtName") as TextBox).Text, " "); } } } } }
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %> <!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> <form id="form1" runat="server"> </form> </html>
check.id="check"+item.IMAGE_ID;
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionfor (int i = 0; i <= rptNotering.Items.Count - 1; i++) { Button delete = (Button)rptNotering.Items[i].FindControl("btnDelete"); delete.Visible = true; Button edit = (Button)rptNotering.Items[i].FindControl("btnEdit"); edit.Visible = true; }
//Checkbox check = new CheckBox(); check.Visible = true; check.ID = "check"; check.Text = " A supprimé "; check.EnableViewState = true; check.CausesValidation = true; //Repeater rptNew = new Repeater(); rptNew.ID = "rpt" + i; rptNew.Controls.Add(check); rptNew.Controls.Add(Img); public static string Checkbox_verif(Control c) { string checkid = null; if (c != null) { foreach (Control item in rptNew.Parent.Controls) { if (item.Controls.Count > 0) { if (item is Repeater) { foreach (Control item1 in item.Controls) { if (item1 is CheckBox) {//la j'y arrive mais checked = false if ((item1 as CheckBox).Checked) { checkid += (item1.ID + "/"); } } } } } } } if(checkid != null) return checkid; else return null; }