Fetching control values from a gridview TemplateField

Fetching control values from a gridview TemplateField

am 03.01.2008 15:51:55 von 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).FindCon trol("lblUser"),
Label).Text ' Empty
End Sub

DataSourceID="sdsCustOrders"
runat="server" AllowSorting="True"
OnSelectedIndexChanged="grdOrders_SelectedIndexChanged">







<%#Eval("UserName")%> asp:Label>



Re: Fetching control values from a gridview TemplateField

am 03.01.2008 16:16:32 von Eliyahu Goldin

Your FindControl call is fine. The problem could be that Label.Text doesn't
come back in the postback. Replace the label with a textbox and see if it
works.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


wrote in message
news:b164cc2b-c947-4391-8c51-63f337542a73@f3g2000hsg.googleg roups.com...
>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).FindCon trol("lblUser"),
> Label).Text ' Empty
> End Sub
>
> > DataSourceID="sdsCustOrders"
> runat="server" AllowSorting="True"
> OnSelectedIndexChanged="grdOrders_SelectedIndexChanged">
>
>
>
>
>
>
>
> <%#Eval("UserName")%> > asp:Label>
>

>

>

>

Re: Fetching control values from a gridview TemplateField

am 03.01.2008 16:50:33 von 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!

Re: Fetching control values from a gridview TemplateField

am 03.01.2008 17:00:30 von msch.prv

Right on the bull's eye, Eliyahu! Thank you very much!

Happy New Year.