Every time I attempt to retrieve a value from a textbox, I encounter this error (as shown in the image) and I am at a loss as to how to resolve it. My code is as follows:
protected void Button3_Click(object sender, EventArgs e)
{
_controller = new Controller();
//Variables
string appointment ="";
foreach (GridViewRow row in GridView1.Rows)
{
appointment = ((TextBox)row.FindControl("txtEditTabel")).Text;
}
I am using a combination of javascript and ASP.NET, and the code appears like this; additional information about the JavaScript: EDITABLE LABEL
JAVASCRIPT (which changes a label to a textbox when clicked)
$(function () {
//Loop through all Labels with class 'editable'.
$(".editable").each(function () {
//Reference the Label.
var label = $(this);
//Add a TextBox next to the Label.
label.after("<input type = 'text' style = 'display:none' />");
//Reference the TextBox.
var textbox = $(this).next();
//Set the name attribute of the TextBox.
var id = this.id.split('_')[this.id.split('_').length - 1];
//textbox[0].name = id.replace("Label","Textbox"); //tis dit hier van die id's
textbox[0].name = "txtEditTabel";
//Assign the value of Label to TextBox.
textbox.val(label.html());
//When Label is clicked, hide Label and show TextBox.
label.click(function () {
$(this).hide();
$(this).next().show();
});
//When focus is lost from TextBox, hide TextBox and show Label.
textbox.focusout(function () {
$(this).hide();
$(this).prev().html($(this).val());
$(this).prev().show();
});
});
});
ASP.NET
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" Width="1000px" HorizontalAlign="Center" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField HeaderText="IDAfspraken">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Eval("IDAfspraken") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</asp:GridView>
I have double-checked my SQL code and believe it to be correct. Is there something I am overlooking? Any assistance would be greatly appreciated!