Det var i hvert fald så lidt :o)
Du kan bare få det her (der er ikke så meget mere end der var i det andet) :
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using ExpArticles.ExpData;
namespace EXP2
{
public class RepeaterSager : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Repeater Repeater1;
protected System.Web.UI.WebControls.Repeater ChildRepeater;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
SampleDataSet ds = new ExpArticles.ExpData.ExpDataAccess().GetSampleData(10);
Repeater1.DataSource = ds;
DataBind();
}
}
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Repeater1.ItemCreated += new RepeaterItemEventHandler(Repeater1_ItemCreated);
this.Repeater1.ItemDataBound += new System.Web.UI.WebControls.RepeaterItemEventHandler(this.Repeater1_ItemDataBound);
this.Load += new System.EventHandler(this.Page_Load);
}
protected void chkCheck_CheckedChanged(object sender, EventArgs e)
{
CheckBox c = (CheckBox)sender;
RepeaterItem r = (RepeaterItem)c.Parent; //Dette virker
int index = r.ItemIndex;
}
private void Repeater1_ItemCreated(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
((CheckBox)e.Item.FindControl("chkCheck")).CheckedChanged += new EventHandler(RepeaterSager_CheckedChanged);
}
private void Repeater1_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
Repeater rep = (Repeater)e.Item.FindControl("ChildRepeater");
if(rep != null)
{
rep.DataSource = GetChildData();
rep.DataBind();
}
}
private void RepeaterSager_CheckedChanged(object sender, EventArgs e)
{
CheckBox c = (CheckBox)sender;
Control container = c.NamingContainer;
RepeaterItem r = (RepeaterItem)c.NamingContainer;
int index = r.ItemIndex;
Response.Write(String.Format("LastItemIndex : {0}", index));
}
protected void ChildCheckBoxCheckedChanged(object sender, EventArgs e)
{
CheckBox c = (CheckBox)sender;
Control container = c.NamingContainer;
RepeaterItem r = (RepeaterItem)c.NamingContainer;
int index = r.ItemIndex;
Response.Write(String.Format("LastItemIndex : {0}", index));
}
protected DataSet GetChildData()
{
return new ExpArticles.ExpData.ExpDataAccess().GetSampleData(5);
}
}
}
// og en aspx-fil
<%@ Page language="c#" Codebehind="RepeaterSager.aspx.cs" AutoEventWireup="false" Inherits="EXP2.RepeaterSager" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>RepeaterSager</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="
http://schemas.microsoft.com/intellisense/ie5"> </HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:Repeater id="Repeater1" runat="server">
<ItemTemplate>
<asp:Label ID="lblName" Runat="server">
Parent : <%# DataBinder.Eval(Container, "DataItem.FldString") %>
</asp:Label>
<br>
<asp:Repeater ID="ChildRepeater" Runat="server">
<ItemTemplate>
<asp:Label ID="Label1" Runat="server">
Child : <%# DataBinder.Eval(Container, "DataItem.FldString") %>
</asp:Label>
<asp:CheckBox ID="chkChildCheck" Runat="server" AutoPostBack="True" OnCheckedChanged="ChildCheckBoxCheckedChanged"></asp:CheckBox>
</ItemTemplate>
<SeparatorTemplate>
<hr>
</SeparatorTemplate>
</asp:Repeater>
<br>
ParentCheckBox
<asp:CheckBox ID="chkCheck" Runat="server" AutoPostBack="True"></asp:CheckBox>
</ItemTemplate>
<SeparatorTemplate>
<hr>
</SeparatorTemplate>
</asp:Repeater>
</form>
</body>
</HTML>
mvh