tcannon
asked on
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-HorizontalAli gn="Left"
HeaderStyle-BackColor="#70 7070"
HeaderStyle-ForeColor="#FF FFFF"
AlternatingRowStyle-ForeCo lor="#FFFF FF"
AlternatingRowStyle-BackCo lor="#A0A0 A0"
FooterStyle-BackColor="#70 7070"
FooterStyle-ForeColor="#FF FFFF"
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("CAP ITAL_PROJ_ NBR")%></a sp: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_RowDeletin g(ByVal sender As Object, ByVal e As System.Web.UI.WebControls. GridViewDe leteEventA rgs) Handles gvProjCapitalNo.RowDeletin g
Dim PID As Integer = gvProjCapitalNo.DataKeys(0 ).Value
Dim lCPN As Label = CType(gvProjCapitalNo.Find Control("l blCPN"), Label)
ProjectDAC.ProjCapitalFund ingDelete( lCPN.Text, PID)
End Sub
ERROR MESSAGE IS: "Object reference not set to an instance of an object" on this function - ProjectDAC.ProjCapitalFund ingDelete( lCPN.Text, PID)
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-HorizontalAli
HeaderStyle-BackColor="#70
HeaderStyle-ForeColor="#FF
AlternatingRowStyle-ForeCo
AlternatingRowStyle-BackCo
FooterStyle-BackColor="#70
FooterStyle-ForeColor="#FF
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("CAP
</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_RowDeletin
Dim PID As Integer = gvProjCapitalNo.DataKeys(0
Dim lCPN As Label = CType(gvProjCapitalNo.Find
ProjectDAC.ProjCapitalFund
End Sub
ERROR MESSAGE IS: "Object reference not set to an instance of an object" on this function - ProjectDAC.ProjCapitalFund
ASKER
I get the value for PID, but no value for the label CPN
When you get to that line, does FindControl("lblCPN") find anything or is it equal to nothing?
ASKER
It is equal to nothing.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Closed, 250 points refunded.
Vee_Mod
Community Support Moderator
Vee_Mod
Community Support Moderator
Can you run the debugger and find the values of PID and ICPN.Text when you hit the line
ProjectDAC.ProjCapitalFund