Solved

cant find label in gridview

Posted on 2011-02-24
3
522 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
call function 8 40
Voice recognition ASP or ASP.NET or JavaScript 2 45
Asp.net mvc entity issue 6 20
Jquery autocomplete 10 30
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now