Solved

cant find label in gridview

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

713 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