maqskywalker
asked on
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:TextB ox>
</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 ("txtLastN ame"), TextBox)
firstnameText = CType(dataItem.FindControl ("txtFirst Name"), TextBox)
paramLastName = lastnameText.Text.ToString ().Trim()
paramFirstName = firstnameText.Text.ToStrin g().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?
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.
runat="server"></asp:TextB
</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
firstnameText = CType(dataItem.FindControl
paramLastName = lastnameText.Text.ToString
paramFirstName = firstnameText.Text.ToStrin
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER