troubleshooting Question

using wildcard with FindControl in C# or VB

Avatar of maqskywalker
maqskywalker asked on
ASP.NETVisual Basic.NET
2 Comments1 Solution274 ViewsLast Modified:
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?
ASKER CERTIFIED SOLUTION
GMGenius
Software Development Manager/Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros