Fetching control values from a gridview TemplateField

M

msch.prv

I have a gridview wich contains a mix of boundfields and
templatefields. While the boundfields can be retrieved w/o problems, I
am at a loss to get the values of the template fields. I googled
around and tried various methods to no avail.

TIA for any pointers.

Protected Sub grdOrders_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs)
Dim rowIdx As Integer = Me.grdOrders.SelectedRow.RowIndex
Dim strTmp As String

strTmp = Me.grdOrders.Rows(rowIdx).Cells(0).Text ' first column
strTmp = Me.grdOrders.Rows(rowIdx).Cells(1).Text ' Works OK
strTmp = CType(Me.grdOrders.Rows(rowIdx).FindControl("lblUser"),
Label).Text ' Empty
strTmp = CType(Me.grdOrders.Rows(rowIdx).Cells(2).Controls(1),
Label).Text ' Empty
strTmp =
CType(Me.grdOrders.Rows(rowIdx).Cells(2).Controls(1).FindControl("lblUser"),
Label).Text ' Empty
End Sub

<asp:GridView ID="grdOrders" DataKeyNames="OBaseID"
DataSourceID="sdsCustOrders"
runat="server" AllowSorting="True"
OnSelectedIndexChanged="grdOrders_SelectedIndexChanged">
<Columns>
<asp:CommandField ShowSelectButton="True" />

<asp:BoundField DataField="UserName" HeaderText="Status" />

<asp:TemplateField HeaderText="User" >
<ItemTemplate>
<asp:Label ID="lblUser" runat="server"><%#Eval("UserName")%></
asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
 
M

msch.prv

Right on the bull's eye, Eliyahu! Thank you very much! I spent quite a
few hours trying to figure this out.

Happy New Year!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top