Repeater
Repeater is a data control.
It is used to display the controls in repeated manner.
Repeater Control Event Handling [Using Eval()]
In order to attain Event Handling we have to create two events.
1. Event of repeater's itself-
OnItemCommand
2. Event of the control inside the repeater-
CommandName
Note:- we don't use onClick Event for controls in repeater.
------------------------------------
Format-
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="repeat_click">
<ItemTemplate>
<img src='/file_name<%# Eval("column_name") %>' height="100px" width="100px"/>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("column_name")%>'></asp:Label>
<asp:Button ID="Btn1" runat="server" Text="Submit" CommandName="submit_click" />
</ItemTemplate>
</asp:Repeater>
Coding-
//Creating the Event of repeater in .aspx.cs-
protected void repeat_click(object source, RepeaterCommandEventArgs e)
{
if(e.CommandName=="submit_click")
{
//finding the control
Button b1 = (Button)e.Item.FindControl("Btn1");
//logic about the button here
Response.Write(Button1.Text);
}
}
Comments
Post a Comment