using wildcard with FindControl in C# or VB

i'm using ASP.NET Web Forms and DataGrid using VB.

In my DataGrid one of my columns is the lastName column.
This is the markup in the grid for that column

                    <asp:TemplateColumn HeaderText="LastName">
                        <ItemTemplate>
                            <asp:TextBox ID="txtLastName" Width="30"
                                Text='<%# DataBinder.Eval(Container.DataItem, "LastName").ToString()%>'
                                runat="server"></asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateColumn>


Now in the vb code for the page on my button click event

I get the value of the textbox and save it in a variable using FindControl like this:

    Protected Sub Button1_Click(ByVal send As Object, ByVal E As EventArgs)

        Dim lastnameText As TextBox = New TextBox()
        Dim firstnameText As TextBox = New TextBox()

        For Each dataItem As DataGridItem In DGEmployees.Items

            lastnameText = CType(dataItem.FindControl("txtLastName"), TextBox)
            firstnameText = CType(dataItem.FindControl("txtFirstName"), TextBox)
            paramLastName = lastnameText.Text.ToString().Trim()
            paramFirstName = firstnameText.Text.ToString().Trim()

        Next

    End Sub



When using FindControl is there a way to use a wild card?
Or  
Some other way to find the textbox whose id starts with or textbox whose id ends with?
LVL 1
maqskywalkerAsked:
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.

GMGeniusSoftware Development Manager/DeveloperCommented:
The FindControl does not allow wildcard so your best option is to iterate through all controls in the container using your pattern matching

For example

           
            for (int i = 0; i < container.Controls.Count; i++)
            {
                if (container.Controls[i].ID.StartsWith("idstart") && container.Controls[i].ID.EndsWith("end"))
                {
                	// found it
                }
            }

Open in new window

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
maqskywalkerAuthor Commented:
thanks
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.