Solved

cant find label in gridview

Posted on 2011-02-24
3
528 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

695 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