Solved

cant find label in gridview

Posted on 2011-02-24
3
524 Views
Last Modified: 2012-08-13
I have the gridview below.

In my code behind I then have:
 Protected Sub gvInvoiceQueries_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvInvoiceQueries.RowDataBound
        Dim invoice As Invoice = Nothing
        Dim lblPaymentType As Label = Nothing

        Try
            Select Case e.Row.RowType
                Case DataControlRowType.DataRow
                    lblPaymentType = CType(e.Row.FindControl("lblPaymentType"), Label)

The label is nothing so isn't being found.

What am I doing wrong?
<asp:GridView  ID="gvInvoiceQueries" runat="server" CssClass="gridviewheader" AutoGenerateColumns="False" > 
     <Columns>
            <asp:TemplateField HeaderText="Query Type">     
                <ItemTemplate>
                    <asp:Label ID="lblQueryType" runat="server" Text='<%#Bind("QueryType.Description")%>'></asp:Label>                                        
                </ItemTemplate>                                 
            </asp:TemplateField> 
            <asp:TemplateField HeaderText="Payment Type">     
                <ItemTemplate>
                    <asp:Label ID="lblPaymentType" runat="server" Text=''></asp:Label>                                        
                </ItemTemplate>                                 
            </asp:TemplateField>

Open in new window

0
Comment
Question by:scm0sml
  • 2
3 Comments
 
LVL 14

Expert Comment

by:robasta
ID: 34969055
0
 

Author Comment

by:scm0sml
ID: 34969071
i dont need to loop through like that there is a way of doing it as i am I just can't remember the exact syntax or logic............

Your page does mention the find control which is how I am doing it but doesn't go into much detail.
0
 
LVL 14

Accepted Solution

by:
robasta earned 500 total points
ID: 34969177
that code you posted initially should work. e.Row.FindControl(xx)

i used it in c# and it got the label. i then converted to VB and it gave me :

If e.Row.RowType = DataControlRowType.DataRow Then
      Dim l As Label = DirectCast(e.Row.FindControl("lblPaymentType"), Label)
      l.Text = "rob"
End If
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question