Saturday, January 07, 2006
If you have a button or any other form inside a repeater, and you want to delete a row or do any work on some row, and you want to know the data there, well here's the solution;
1. lets assume you have the following button in the <ItemTemplate> tag of a repeater
<
asp:Button ID="btnEdit" runat="server" EnableViewState="false"Text="Edit" CommandName="Edit"/>
2. double click on the repeater on the Design view, you'll get the following method, all you have to do is the following;
protected void rptrTestRepeater_ItemCommand(object source , RepeaterCommandEventArgs e)
{
int v1;
/// find the CommandName you specified for the button
if ( e.CommandName == "Edit")
{
/// Get the index, the location, the row index in the repeater
v1 = e.Item.ItemIndex;
/// find a certain control in that row that you have in the repeater, like a label or texbox
Label LabelTemp = (Label)rptrTestRepeater.Items[v1].FindControl("lblTestLabel");
/// do whatever work you want with this Temporarily form, LabelTemp here
}// end if
}
Saturday, January 07, 2006
sometimes you wanna iterate through a number of forms in a repeater, like a checkbox or a button, and do some work for these on the aspx.cs page, all what you have to do is the following:
1. Add the form to the <ItemTemplate> tag in the repeater
ex. <asp:CheckBox ID="chkbox" runat="server" EnableViewState="false"/>
2. In the code do the following; ex.
///Iterate through the repeater
for(inti = 0; i < rptrTestRepeater.Items.Count; i++)
{
///Find the control you have specified, here a checkbox, with an ID=chkbox, and assign this check box
/// to a temporarily checkbox, then you can do whatever you wish with the temp checkbox
CheckBoxchkboxTemp = (CheckBox)rptrTestRepeater.Items[i].FindControl("chkbox");
///IF THE CHECKBOX IS CHECKED, Do bla bla
if(chkboxTemp.Checked == true)
{
//Do some work!
}
}// end of for loop
<<Home