Critical Developers

Programmers Knowledge Base

Accessing DataItem, ItemIndex etc. of Parent Repeater in Child Repeater

IN GUI:-

Write following line in any of Template in child repeater

eg-1: in Child Repeater (for accessing ItemIndex of Parent Repeater)
<ItemTemplate>
<%# ((RepeaterItem)Container.Parent.Parent).ItemIndex %>
</ItemTemplate>

eg-2: in Child Repeater (for accessing DataItem of Parent Repeater)
<ItemTemplate>
<%# DataBinder.Eval(((RepeaterItem)Container.Parent.Parent).DataItem, "COL_NAME") %>
</ItemTemplate>

IN CODE BEHIND:-

Write following line in ItemDataBound Event of child repeater

eg-1: in Child Repeater (for accessing ItemIndex of Parent Repeater)
Convert.ToString(DataBinder.Eval(((RepeaterItem)e.Item.Parent.Parent).DataItem, "COL_NAME"));


eg-2: in Child Repeater (for accessing DataItem of Parent Repeater)
Convert.ToInt32((((RepeaterItem)e.Item.Parent.Parent).ItemIndex));

Export Multiple GridView to Excel

Dim heading As String = ""
Dim heading1 As String = ""
heading = "<center><h1>All-Members</h1></center><br />"
Dim filename As String = "All-Grid-Details" & CStr(Date.Today.Day & Date.Today.ToString("MM") & Date.Today.Year) & ".xls"
Dim form As New HtmlForm()
GridView1.AllowPaging = False
BindGrid1()
GridView2.AllowPaging = False
BindGrid2()
GridView3.AllowPaging = False
BindGrid3()
GridView4.AllowPaging = False
BindGrid4()
GridView5.AllowPaging = False
BindGrid5()
Response.ClearContent()
Dim attachment As String = "attachment; filename=" & filename
Response.ClearContent()
Response.AddHeader("content-disposition", attachment)
Response.ContentType = "application/ms-excel"
Dim stw As New StringWriter()
Dim htextw As New HtmlTextWriter(stw)
form.Controls.Add(Label1)
form.Controls.Add(GridView1)
form.Controls.Add(Label2)
form.Controls.Add(GridView2)
form.Controls.Add(Label3)
form.Controls.Add(GridView3)
form.Controls.Add(Label4)
form.Controls.Add(GridView4)
form.Controls.Add(Label5)
form.Controls.Add(GridView5)
Me.Controls.Add(form)
form.RenderControl(htextw)
Response.Write(heading)
Response.Write(stw.ToString())
Response.End()