Anti BloGging Association
_________The BlogName Contradicts with the Real Content ;) zzzz

asp Button inside a repeater, using CommandName ASP.Net 2.0 C#

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
}

(0) comments

multiple checkbox or textbox or any form in repeater ASP.Net 2.0 C#

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

(2) comments


<<Home

This is my Google PageRank™ - SmE Rank free service Powered by Scriptme

HoUzeR -Omar Abu Arisheh- 2005-2006