Hi I'm not really good at programming thus I need some guidance from you experts.
I'm using Visual Studio 2005, asp.net, C#.
I wanted to add things into my database when the user clicks the add button that is created in the item template field of the GridView control. This is how my item template field looks like:
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:Button ID="AddBT" runat="server" CausesValidation="False"
OnClick="AddBT_Click" Text="Add to Cart" CommandName="Delete" />
</ItemTemplate>
<ControlStyle Width="80px" />
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:Button ID="AddBT" runat="server" CausesValidation="False" OnClick="AddBT_Click" Text="Add to Cart" />
</ItemTemplate>
<ControlStyle Width="80px" />
</asp:TemplateField>
So every line in the gridview will have the Add button.
So on click it will run the codes that is on my .cs file and this is when I recieve this error "Object reference not set to an instance of an object."
I slowly elimate the code and found out that the source of the problem is this:
string eID = GridView1.SelectedRow.Cells[2].Text;
Apparently SelectedRow, SelectedIndex and SelectedDataKey etc will give me the same error message.
Can anyone help me with this? Couldn't find my answer after Googling it for hours.