change the textbox name

I have a function which will delete the text in a textbox.  I have attached the code in the code window. "row" is a string value which I want to attach to the textbox name so  I can get actual textbox name. the syntax that I have is not right.  what do i need to do in order to attach a stringvalue to the textboxname to get the correct name

protected void DeleteRow( string row)
{
textbox + row .Text = "";
// row = 2
// so what i want to do is 
//textbox2.Text = "";

}

Open in new window

pratikshahseAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shaun KlineLead Software EngineerCommented:
You can use the FindControl method to find controls by their name. As a example:

((TextBox)Page.FindControl("myTextBox" + row)).Text = string.empty;

In this example, Page is the container for "myTextBox1".

If your textbox is in a gridview, you need to use the gridviewrow that contains the textbox.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LotokCommented:
I know you are c# but here is the solution in vb.net

The example assumes the textbox is just on a page and not embedded in placeholders, data controls like gridviews or panels.

If in a panel it would just be

Dim tmp as textbox = Ctype(pnPanelName.findcontol("textbox" & row), textbox))
tmp.text = ""
Public Sub DeleteRow(byval row as string)

Dim tmp as textbox = Ctype(Page.findcontol("textbox" & row), textbox))
tmp.text = ""


End Sub

Open in new window

0
rajeeshmcaCommented:
Hi pratikshahse,

U cannot assign the Text as u have done... The thing is it takes that (textbox + row) as a string and will not consider as a id of the Text Box.. u Should go with the approach suggested by Shaun_Kline...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.