How To Delete a Row in GridView?

How do I delete a row in a GridView?

Here's my code so far:
.aspx file

<asp:GridView id="gvProjCapitalNo"
      Runat="Server"
      AutoGenerateColumns="False"
      ShowFooter="True"
      Caption="<b></b>"
      CellPadding="0"
      BorderStyle="None"
      BorderWidth="1px"
      BackColor="White"
      Font-Size="10pt"
      EditRowStyle-HorizontalAlign="Left"
      HeaderStyle-BackColor="#707070"
      HeaderStyle-ForeColor="#FFFFFF"
      AlternatingRowStyle-ForeColor="#FFFFFF"
      AlternatingRowStyle-BackColor="#A0A0A0"
      FooterStyle-BackColor="#707070"
      FooterStyle-ForeColor="#FFFFFF"
      FooterStyle-Font-Size="7pt"
      AllowPaging="false"
      AllowSorting="true"
      Font-Names="Verdana"
      Width="350px"
      PageSize="25"
      BorderColor="#E7E7FF"
      GridLines="Horizontal"
      DataKeyNames="PROJ_REF_NBR">

  <Columns>
 
  <asp:CommandField ShowDeleteButton="true" />  
   
  <asp:BoundField
    DataField="PROJ_REF_NBR"
     Visible="false"
    HeaderText="Project ID">
      <FooterStyle BorderWidth="0px" />
  </asp:BoundField>
 
  <asp:TemplateField HeaderText="CAPITAL PROJECT NUMBER">
    <ItemTemplate>
        <asp:Label ID="lblCPN" runat="server"> <%#Container.DataItem("CAPITAL_PROJ_NBR")%></asp:Label>
    </ItemTemplate>    
  </asp:TemplateField>
 
  </Columns>
     <FooterStyle BackColor="#B5C7DE" Font-Size="7pt" ForeColor="#4A3C8C" />
     <HeaderStyle BackColor="#4A3C8C" ForeColor="#F7F7F7" Font-Bold="True" />
     <AlternatingRowStyle BackColor="#F7F7F7" ForeColor="#4A3C8C" />
     <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
     <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
     <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />

</asp:GridView>

.aspx.vb file code:

Protected Sub gvProjCapitalNo_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles gvProjCapitalNo.RowDeleting

        Dim PID As Integer = gvProjCapitalNo.DataKeys(0).Value
        Dim lCPN As Label = CType(gvProjCapitalNo.FindControl("lblCPN"), Label)

        ProjectDAC.ProjCapitalFundingDelete(lCPN.Text, PID)

    End Sub

ERROR MESSAGE IS: "Object reference not set to an instance of an object" on this function - ProjectDAC.ProjCapitalFundingDelete(lCPN.Text, PID)
tcannonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cmhuntyCommented:
The error is in ProjectDAC.ProjCapitalFundingDelete or on the line that calls it?

Can you run the debugger and find the values of PID and ICPN.Text when you hit the line
ProjectDAC.ProjCapitalFundingDelete(lCPN.Text, PID)?
0
tcannonAuthor Commented:
I get the value for PID, but no value for the label CPN
0
cmhuntyCommented:
When you get to that line, does FindControl("lblCPN") find anything or is it equal to nothing?
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

tcannonAuthor Commented:
It is equal to nothing.
0
tcannonAuthor Commented:
I decided to store the data that I needed to delete the row in query string, then pass that into my delete function. Kind of a round about way, but it got the job done.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vee_ModCommented:
Closed, 250 points refunded.
Vee_Mod
Community Support Moderator
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.