Jump to content

Button And Itemtemplate Name If More Than One Row


soona

Recommended Posts

Hi,In Repeater1 control after more than one row. next row will display button and Itemtemplate name.For example:In repeator control listed outpinkblueWhiteFrom this example i would like to change this likepinkblue button1(event)white button2(event)----------This is my existing code. i need to modify the above example.category.aspx<asp:PlaceHolder ID="panel1" runat="server"><ul><asp:Repeater ID="Repeater1" runat="server"><ItemTemplate><li ><asp:Literal ID="Label1" runat="server" Text='<%#Eval("Name")%>' /></li></ItemTemplate></asp:Repeater></ul></asp:PlaceHolder>category.aspx.csCategories Cat = GetItems(_Item1);panel1.Visible = (Cat.Count > 0);if (panel1.Visible){Repeater1.DataSource = Cat;Repeater1.DataBind();}How can i do ?Thanks

Link to comment
Share on other sites

One way could be like this:In your ASPX

<asp:PlaceHolder ID="panel1" runat="server"><ul><asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound"><ItemTemplate><li>	<asp:Literal ID="Label1" runat="server" Text='<%#Eval("Name")%>' />	<asp:Button ID="Button1" runat="server" Text="This is a Button!" Visible="false" /></li></ItemTemplate></asp:Repeater></ul></asp:PlaceHolder>

Then, in the code-behind:

private int count = 0;protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e){	RepeaterItem item = e.Item;	switch(item.ItemType)	{		case ListItemType.Item:		case ListItemType.AlternatingItem:			Button button = item.FindControl("Button1") as Button;			if(button != null)			{				 if(count >0)				 {					  button.Visible = true;					  // OnClick could be assigned here...				 }				 count++;			}			break;	}}

For more information, check out the ItemDataBound event:http://msdn.microsoft.com/en-us/library/sy...mdatabound.aspx

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...