marcusstarnes
marcusstarnes

Reputation: 6531

Get multiple textbox values from repeateritem control that triggered event

I have a Repeater control that outputs various forum posts on the page.

Within each repeater row, I have a LinkButton and 4 TextBoxes that contain values.

When I click on one of the LinkButtons, in my event handler code, I want to get the values that are in each of the 4 TextBoxes that correspond with that one particular repeater item/row.

I can repeat through each item within the repeater, but I am only interested in the values that exist in the 4 textboxes that sat alongside the LinkButton that was clicked/that triggered the event. I'm not interested in any of the Textbox values that belong to the other rows/items within the repeater.

What's the best way to do this?

Upvotes: 0

Views: 1519

Answers (1)

Aghilas Yakoub
Aghilas Yakoub

Reputation: 28970

You can use with ItemCommand event and e.Item.FindControl

Link : http://msdn.microsoft.com/fr-fr/library/system.web.ui.webcontrols.repeater.itemcommand.aspx

    protected void Repeater_ItemCommand(object source, RepeaterCommandEventArgs e) 
    {
        if(e.CommandName == "YourCommand" ) //Adjust your CommandName
        {
            var textbox1 = (TextBox)e.Item.FindControl("YourIdTextBox1");  //Adjust your Id of TextBox  in row   
            var textbox2 = (TextBox)e.Item.FindControl("YourIdTextBox2"); 
            var textbox3 = (TextBox)e.Item.FindControl("YourIdTextBox3"); 
            var textbox4 = (TextBox)e.Item.FindControl("YourIdTextBox4"); 

            ....
        }
    }

Upvotes: 1

Related Questions