I have a gridview with a template field column which has an image button using 'select' command.
I am trying to get the value of a hidden column from the selected row and parse it as a parameter to add it to a database.
In my code behind I have for getting value:
Using as a parameter in my stored procedure:
I am getting the error 'Object reference not set to an instance of an object.' on the line
Any ideas
Code:
<asp:TemplateField ShowHeader="False" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:ImageButton ID="btnSelect" runat="server" CausesValidation="False" ImageUrl="images/select_icon.png"
CommandName="Select" Text="Select" OnClick="LinkButton1_Click"
/>
</ItemTemplate>
</asp:TemplateField>
I am trying to get the value of a hidden column from the selected row and parse it as a parameter to add it to a database.
In my code behind I have for getting value:
Code:
Protected Sub LinkButton1_Click(sender As Object, e As EventArgs)
Dim clickedRow As GridViewRow = TryCast(DirectCast(sender, ImageButton).NamingContainer, GridViewRow)
Dim lblID As Label = DirectCast(clickedRow.FindControl("CertificateID"), Label)
lblSelectedRecord.text = lblID.Text
End Sub
Using as a parameter in my stored procedure:
Code:
cmd.Parameters.Add("@CertificateID", SqlDbType.Int).Value = lblSelectedRecord.Text.Trim
I am getting the error 'Object reference not set to an instance of an object.' on the line
Code:
blSelectedRecord.text = lblID.Text
Any ideas