Oh dear -
I don't know how it came to this but I could really do with a bit of help.


I have a gridview which has editable columns.
The gridview lives in a formview, which lives in another formview.

Inside one column is an end date. This column has a textbox which gets it's value when I choose a date from a calendar control. However, when I choose a date from the calendar control, the program crashes instead of populating the text box.

Here is the page and the selectedIndexChanged sub for the piece of work I'm trying to accomplish...


Code VBNET:
 
dim rowid as integer
 
Protected Sub Calendar2_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        'Assign value to textbox from Calendar
        Dim tmp As FormView = Me.FormView1.FindControl("formview3")
        Dim tmpgridview As GridView = tmp.FindControl("gridview2")
        CType(tmpgridview.Rows(rowid).FindControl("textbox3"), TextBox).Text = CType(tmpgridview.Rows(rowid).FindControl("Calendar2"), Calendar).SelectedDate
    End Sub

Gridview2 is inside formview3 inside formview1
I have included the whole page below, but the problem area is gridview2

Code VBNET:
<&#37;@ Page Language="VB" MasterPageFile="~/myMasterPage.master" AutoEventWireup="false" CodeFile="user_profile.aspx.vb" Inherits="user_profile" title="View Profile - Add/Remove Skills and Services" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script language="javascript" type="text/javascript">
// <!CDATA[
 
 
 
// ]]>
</script>
    <asp:FormView ID="FormView1" runat="server" DataKeyNames="staff_payroll_int" DataSourceID="SqlDataSource1" Width="98%">
        <EditItemTemplate><br />
            <label for="staff_forename_strTextBox">
                Forename:</label>
            <asp:TextBox ID="staff_forename_strTextBox" runat="server" Text='<%# Bind("staff_forename_str") %>'></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="staff_forename_strTextBox"
                ErrorMessage="Forename Required"></asp:RequiredFieldValidator><br />
            <label for="staff_surname_strTextBox" style="color: #102163">
                Surname:</label>
            <asp:TextBox ID="staff_surname_strTextBox" runat="server" Text='<%# Bind("staff_surname_str") %>'></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="staff_surname_strTextBox"
                ErrorMessage="Surname Required"></asp:RequiredFieldValidator><br />
            <label for="ddi_primary_number_strTextBox" style="color: #102163">
                DDI Primary:</label>
            <asp:TextBox ID="ddi_primary_number_strTextBox" runat="server" Text='<%# Bind("ddi_primary_number_str") %>'></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="ddi_primary_number_strTextBox"
                ErrorMessage="DDI Primary Required" Display="Dynamic" ></asp:RequiredFieldValidator>
                <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="ddi_primary_number_strTextBox"
                Display="Dynamic" ErrorMessage="11 Digit Number Required" ValidationExpression="\d{11}"></asp:RegularExpressionValidator><br/>
            <label for="ddi_secondary_number_strTextBox">
                DDI Secondary:</label>
            <asp:TextBox ID="ddi_secondary_number_strTextBox" runat="server" Text='<%# Bind("ddi_secondary_number_str") %>'></asp:TextBox> <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ControlToValidate="ddi_secondary_number_strTextBox"
                Display="Dynamic" ErrorMessage="11 Digit Number Required" ValidationExpression="\d{11}"></asp:RegularExpressionValidator><br />
            <label for="phone_type_id_intTextBox">
                Phone Type:</label>
            <asp:DropDownList ID="phone_type_id_intTextBox" runat="server" AppendDataBoundItems="True"
                DataSourceID="SqlDataSource3" DataTextField="phone_type_name_str" DataValueField="phone_type_id_int" SelectedIndex='<%# Bind("phone_type_id_int") %>'>
                <asp:ListItem Value="0" Selected="True">Choose Phone Type</asp:ListItem>
            </asp:DropDownList>
            <asp:RangeValidator ID="RangeValidator4" runat="server" ControlToValidate="phone_type_id_intTextBox"
                Display="Dynamic" ErrorMessage="Phone Type Required" MaximumValue="2" MinimumValue="1"></asp:RangeValidator>
            <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:IPTelephonyConnectionString %>"
                SelectCommand="SELECT * FROM [phone_type]"></asp:SqlDataSource>
            &nbsp;
            <br />
            <br />
            <label for="DropDownList1">
                Branch:</label>
            <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1"
                DataTextField="branch_name_str" DataValueField="branch_id_int" AppendDataBoundItems="True" SelectedValue='<%# Bind("branch_id_int") %>'>
            </asp:DropDownList>
            <asp:RangeValidator ID="RangeValidator2" runat="server" ControlToValidate="DropDownList1"
                ErrorMessage="Branch Required" MaximumValue="999" MinimumValue="1"></asp:RangeValidator>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:IPTelephonyConnectionString %>"
                SelectCommand="SELECT * FROM [branch]"></asp:SqlDataSource>
            <br />
            <label for="team_name_str">
                Team:</label><asp:DropDownList ID="dropdownlist2" runat="server" DataSourceID="SqlDataSource2"
                DataTextField="team_name_str" DataValueField="team_id_int" EnableViewState="False" OnSelectedIndexChanged="dropdownlist2_SelectedIndexChanged" AutoPostBack="True" AppendDataBoundItems="True">
                    <asp:ListItem Value="0">Choose Team</asp:ListItem>
                </asp:DropDownList>&nbsp;
            <asp:TextBox ID="team_id_intTextBox" runat="server" Text='<%# Bind("team_id_int") %>' Visible="False"></asp:TextBox>
            <asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="team_id_intTextBox"
                ErrorMessage="Team Required" MaximumValue="9999" MinimumValue="1"></asp:RangeValidator>
            <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:IPTelephonyConnectionString %>"
                SelectCommand="SELECT * FROM [team] WHERE ([branch_id_int] = @branch_id_int)">
                <SelectParameters>
                    <asp:ControlParameter ControlID="DropDownList1" DefaultValue="1" Name="branch_id_int"
                        PropertyName="SelectedValue" Type="Int32" />
                </SelectParameters>
            </asp:SqlDataSource>
            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                Text="Update">
            </asp:LinkButton>
            <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                Text="Cancel">
            </asp:LinkButton>
        </EditItemTemplate>
        <InsertItemTemplate>
        <h1>Add New Profile</h1>
            <label for="staff_payroll_intTextBox">
                <strong>Staff Payroll Number:</strong></label>
            <asp:TextBox ID="staff_payroll_intTextBox" runat="server" Text='<%# Bind("staff_payroll_int") %>' ></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="staff_payroll_intTextBox"
                ErrorMessage="Must Enter Payroll Number"></asp:RequiredFieldValidator><br />
            <label for="staff_forename_strTextBox">
                <strong>Forename:</strong></label>
            <asp:TextBox ID="staff_forename_strTextBox" runat="server" Text='<%# Bind("staff_forename_str") %>'></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="staff_forename_strTextBox"
                ErrorMessage="Forename Required"></asp:RequiredFieldValidator><br />
            <label for="staff_surname_strTextBox">
                <strong>Surname:</strong></label>
            <asp:TextBox ID="staff_surname_strTextBox" runat="server" Text='<%# Bind("staff_surname_str") %>'></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="staff_surname_strTextBox"
                ErrorMessage="Surname Required"></asp:RequiredFieldValidator><br />
            <label for="ddi_primary_number_strTextBox">
                <strong>DDI Primary:</strong></label>
            <asp:TextBox ID="ddi_primary_number_strTextBox" runat="server" Text='<%# Bind("ddi_primary_number_str") %>' MaxLength="11"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="ddi_primary_number_strTextBox"
                ErrorMessage="DDI Primary Required" Display="Dynamic"></asp:RequiredFieldValidator>
            <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="ddi_primary_number_strTextBox"
                Display="Dynamic" ErrorMessage="11 Digit Number Required" ValidationExpression="\d{11}"></asp:RegularExpressionValidator><br />
            <label for="ddi_secondary_number_strTextBox">
                <strong>DDI Secondary:</strong></label>
            <asp:TextBox ID="ddi_secondary_number_strTextBox" runat="server" Text='<%# Bind("ddi_secondary_number_str") %>' MaxLength="11"></asp:TextBox>
            <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="ddi_secondary_number_strTextBox"
                Display="Dynamic" ErrorMessage="11 Digit Number Required" ValidationExpression="\d{11}"></asp:RegularExpressionValidator><br />
            <label for="phone_type_id_intTextBox">
                <strong>Phone Type:</strong></label><asp:DropDownList ID="phone_type_id_intTextBox"
                    runat="server" AppendDataBoundItems="True" DataSourceID="SqlDataSource3" DataTextField="phone_type_name_str"
                    DataValueField="phone_type_id_int">
                    <asp:ListItem Selected="True" Value="0">Choose Phone Type</asp:ListItem>
                </asp:DropDownList><asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:IPTelephonyConnectionString %>"
                    SelectCommand="SELECT * FROM [phone_type]"></asp:SqlDataSource>
            <asp:RangeValidator ID="RangeValidator3" runat="server" ControlToValidate="phone_type_id_intTextBox"
                Display="Dynamic" ErrorMessage="Choose Phone Type" MaximumValue="2" MinimumValue="1"></asp:RangeValidator><br />
            <label for="DropDownList1">
                <strong>Branch:</strong></label>
            <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1"
                DataTextField="branch_name_str" DataValueField="branch_id_int" AppendDataBoundItems="True">
                <asp:ListItem Selected="True" Value="0">Choose Branch</asp:ListItem>
            </asp:DropDownList>
            <asp:RangeValidator ID="RangeValidator2" runat="server" ControlToValidate="DropDownList1"
                ErrorMessage="Branch Required" MaximumValue="999" MinimumValue="1"></asp:RangeValidator>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:IPTelephonyConnectionString %>"
                SelectCommand="SELECT * FROM [branch]"></asp:SqlDataSource>
            <br />
            <label for="team_name_str">
                <strong>Team:</strong></label><asp:DropDownList ID="dropdownlist2" runat="server" DataSourceID="SqlDataSource2"
                DataTextField="team_name_str" DataValueField="team_id_int" EnableViewState="False" AutoPostBack="True" OnSelectedIndexChanged="dropdownlist2_SelectedIndexChanged" AppendDataBoundItems="True">
                <asp:ListItem Selected="True" Value="0">Choose Team</asp:ListItem>
            </asp:DropDownList>
            <asp:TextBox CssClass="hidden" ID="team_id_intTextBox" runat="server" Text='<%# Bind("team_id_int") %>'></asp:TextBox>
            <asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="team_id_intTextBox"
                ErrorMessage="Team Required" MaximumValue="9999" MinimumValue="1"></asp:RangeValidator>
            <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:IPTelephonyConnectionString %>"
                SelectCommand="SELECT * FROM [team] WHERE ([branch_id_int] = @branch_id_int)">
                <SelectParameters>
                    <asp:ControlParameter ControlID="DropDownList1" DefaultValue="1" Name="branch_id_int"
                        PropertyName="SelectedValue" Type="Int32" />
                </SelectParameters>
            </asp:SqlDataSource>
            <br />
            <br />
            <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                Text="Insert" ></asp:LinkButton>
            <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                Text="Cancel"></asp:LinkButton>
        </InsertItemTemplate>
 
 
 
 
        <ItemTemplate>
        <div class="profile_panel">
        <h2>Staff Details</h2>
            <label for="staff_payroll_intLabel">
                <strong>Payroll Number:</strong></label>
            <asp:Label ID="staff_payroll_intLabel" runat="server" Text='<%# Eval("staff_payroll_int") %>'></asp:Label><br />
            <label for="staff_forename_strLabel">
                <strong>Forename:</strong></label>
            <asp:Label ID="staff_forename_strLabel" runat="server" Text='<%# Bind("staff_forename_str") %>'></asp:Label><br />
            <label for="staff_surname_strLabel">
                <strong>Surname:</strong></label>
            <asp:Label ID="staff_surname_strLabel" runat="server" Text='<%# Bind("staff_surname_str") %>'></asp:Label><br />
            <label for="ddi_primary_number_strLabel">
                <strong>DDI Primary:</strong></label>
            <asp:Label ID="ddi_primary_number_strLabel" runat="server" Text='<%# Bind("ddi_primary_number_str") %>'></asp:Label><br />
            <label for="ddi_secondary_number_strLabel">
                <strong>DDI Secondary:</strong></label>
            <asp:Label ID="ddi_secondary_number_strLabel" runat="server" Text='<%# Bind("ddi_secondary_number_str") %>'></asp:Label><br />
            <label for="phone_type_id_intLabel">
                <strong>Phone Type:</strong></label>
            <asp:Label ID="phone_type_id_intLabel" runat="server" Text='<%# Eval("phone_type_name_str") %>'></asp:Label><br />
            <label for="team_id_intLabel">
                <strong>Team:</strong></label>
            <asp:Label ID="team_id_intLabel" runat="server" Text='<%# Eval("team_name_str") %>'></asp:Label><br />
            <br />
            <asp:HyperLink ID="HyperLink1" runat="server" Text="Edit" NavigateURL='<%#string.Format("user_profile.aspx?action=edit&staff_id={0}",Request.Querystring("staff_id"))%>' /></div>
 
 
 
            <div class="skill_panel">
            <h2>Skills</h2>
            <h3>Current Skills</h3>
 
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource3" DataKeyNames="skill_id_int,profile_skill_id_int" CssClass="gridview3">
        <Columns>
            <asp:BoundField DataField="Skill" HeaderText="Skill" SortExpression="Skill" />
            <asp:BoundField DataField="skill_id_int" HeaderText="skill_id_int" InsertVisible="False"
                ReadOnly="True" SortExpression="skill_id_int" Visible="False" />
            <asp:BoundField DataField="profile_skill_id_int" HeaderText="profile_skill_id_int"
                InsertVisible="False" ReadOnly="True" SortExpression="profile_skill_id_int" Visible="False" />
                <asp:TemplateField ShowHeader="False">
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="return confirm('Are you sure you want to delete this skill?')" CausesValidation="False" CommandName="Delete"
                        Text="Delete"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <EmptyDataTemplate>
            No skills currently associated
        </EmptyDataTemplate>
    </asp:GridView>
    <br />
    <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:IPTelephonyConnectionString %>"
        SelectCommand="SELECT skill.skill_name_str AS Skill, skill.skill_id_int, staff_profile_skill_link.profile_skill_id_int FROM skill INNER JOIN staff_profile_skill_link ON skill.skill_id_int = staff_profile_skill_link.skill_id_int WHERE (staff_profile_skill_link.staff_payroll_int = @staff_profile_id)"
        DeleteCommand="DELETE FROM staff_profile_skill_link WHERE profile_skill_id_int = @profile_skill_id_int">
 
        <SelectParameters>
            <asp:SessionParameter DefaultValue="1348460" Name="staff_profile_id" SessionField="staff_profile_id" />
        </SelectParameters>
        <DeleteParameters>
            <asp:Parameter Name="profile_skill_id_int" />
        </DeleteParameters>
    </asp:SqlDataSource>
 
 
 
            <h3>Add Skills</h3>
 
            <asp:FormView ID="FormView2" runat="server" DataKeyNames="skill_id_int" DataSourceID="SqlDataSource1" DefaultMode="Insert" OnItemInserted="FormView2_ItemInserted">
 
        <InsertItemTemplate>
            Choose Skill: 
            <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1"
                DataTextField="skill_name_str" DataValueField="skill_id_int" SelectedValue='<%# Bind("skill_id_int") %>'>
            </asp:DropDownList><br />
            <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                Text="Insert">
            </asp:LinkButton>
            <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                Text="Cancel">
            </asp:LinkButton>
        </InsertItemTemplate>
 
 
    </asp:FormView>
 
    &nbsp;<br />
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:IPTelephonyConnectionString %>"
        SelectCommand="SELECT DISTINCT skill.skill_id_int, skill.skill_name_str FROM skill INNER JOIN team_skill_link ON skill.skill_id_int = team_skill_link.skill_id_int INNER JOIN staff_profile ON team_skill_link.team_id_int = staff_profile.team_id_int WHERE (staff_profile.staff_payroll_int = @staff_profile_id)" 
        InsertCommand="ds_insert_profile_skill_link" InsertCommandType="StoredProcedure">
        <SelectParameters>
            <asp:SessionParameter DefaultValue="1348460" Name="staff_profile_id" SessionField="staff_profile_id" />
        </SelectParameters>
        <InsertParameters>
            <asp:SessionParameter DefaultValue="1348460" Name="staff_payroll_id" SessionField="staff_profile_id" />
            <asp:Parameter Name="skill_id_int" Type="Int32" />
        </InsertParameters>
    </asp:SqlDataSource>
 
 
 
    </div>
            <div class="panel">
            <h2>Services</h2>
            <h3>Current Sevices</h3>
            <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="service_id_int,profile_service_link_id_int"
                DataSourceID="SqlDataSource2" CssClass="gridview3">
                <Columns>
                    <asp:TemplateField HeaderText="service_id_int" InsertVisible="False" SortExpression="service_id_int"
                        Visible="False">
                        <EditItemTemplate>
                            <asp:Label ID="Label2" runat="server" Text='<%# Eval("service_id_int") %>'></asp:Label>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label4" runat="server" Text='<%# Bind("service_id_int") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Service" SortExpression="service_name_str">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("service_name_str") %>' ReadOnly="true"></asp:TextBox>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label3" runat="server" Text='<%# Bind("service_name_str") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="profile_service_link_id_int" InsertVisible="False"
                        SortExpression="profile_service_link_id_int" Visible="False">
                        <EditItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Eval("profile_service_link_id_int") %>' ReadOnly="true"></asp:Label>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label2" runat="server" Text='<%# Bind("profile_service_link_id_int") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Start Date" SortExpression="service_start_date">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("service_start_date","{0:d}") %>' ReadOnly="true"></asp:TextBox>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Eval("service_start_date","{0:d}") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="End Date" SortExpression="service_end_date">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("service_end_date") %>'></asp:TextBox>&nbsp;
                            <asp:ImageButton ID="ImageButton3" runat="server" ImageUrl="~/images/calendar.gif"
                        OnClick="ImageButton3_Click" /><br />
                            <asp:Calendar ID="Calendar2" runat="server" OnSelectionChanged="Calendar2_SelectionChanged" CssClass="calendar">
                                <SelectedDayStyle CssClass="calendarSelectedDay" />
                                <WeekendDayStyle CssClass="calendarWeekendDay" />
                                <TodayDayStyle CssClass="calendarTodayDay" />
                                <DayStyle CssClass="calendarDay" />
                                <DayHeaderStyle CssClass="calendarDayHeader" />
                                <TitleStyle CssClass="calendarTitle" />
                            </asp:Calendar>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label5" runat="server" Text='<%# Bind("service_end_date", "{0:d}") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:CommandField ShowEditButton="True" />
                </Columns>
            </asp:GridView>
            <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:IPTelephonyConnectionString %>"
                SelectCommand="SELECT service.service_id_int, service.service_name_str, staff_profile_service_link.profile_service_link_id_int, staff_profile_service_link.service_start_date, staff_profile_service_link.service_end_date FROM service INNER JOIN staff_profile_service_link ON service.service_id_int = staff_profile_service_link.service_id_int WHERE (staff_profile_service_link.staff_payroll_int = @staff_profile_id)" 
                UpdateCommand="UPDATE staff_profile_service_link SET service_end_date = @service_end_date WHERE (profile_service_link_id_int = @profile_service_link_id_int)">
                <SelectParameters>
                    <asp:QueryStringParameter DefaultValue="1348460" Name="staff_profile_id" QueryStringField="staff_id" />
                </SelectParameters>
                <UpdateParameters>
                    <asp:Parameter Name="service_end_date" />
                    <asp:Parameter Name="profile_service_link_id_int" />
                </UpdateParameters>
            </asp:SqlDataSource>
            <br />
            <h3>Add Services</h3>
            <asp:FormView ID="FormView3" runat="server" DataSourceID="SqlDataSource4" DefaultMode="Insert" Width="100%" DataKeyNames="service_id_int">
                <InsertItemTemplate>
                    <label for="DropDownList3">Choose Service:</label>
                    <asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="SqlDataSource5"
                        DataTextField="service_name_str" DataValueField="service_id_int">
                    </asp:DropDownList><br />
                    <label for="startdate_txtbox">Start Date:</label>
                    <asp:TextBox ID="startdate_txtbox" runat="server"></asp:TextBox>
                    <asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/images/calendar.gif"
                        OnClick="ImageButton2_Click" />
                    <asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged" Visible="false" CssClass="calendar">
                        <SelectedDayStyle CssClass="calendarSelectedDay" />
                        <WeekendDayStyle CssClass="calendarWeekendDay" />
                        <TodayDayStyle CssClass="calendarTodayDay" />
                        <DayStyle CssClass="calendarDay" />
                        <DayHeaderStyle CssClass="calendarDayHeader" />
                        <TitleStyle CssClass="calendarTitle" />
                    </asp:Calendar>
                    <br />
 
                    <asp:SqlDataSource ID="SqlDataSource5" runat="server" ConnectionString="<%$ ConnectionStrings:IPTelephonyConnectionString %>"
                        SelectCommand="SELECT [service_id_int], [service_name_str] FROM [service]"></asp:SqlDataSource>
                    <br />
                    <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
                        Text="Add Service" OnClick="InsertButton_Click"></asp:LinkButton>
                </InsertItemTemplate>
 
 
            </asp:FormView>
            <asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:IPTelephonyConnectionString %>" 
            InsertCommand="ds_insert_profile_service_link" InsertCommandType="StoredProcedure">
                <InsertParameters>
                    <asp:QueryStringParameter QueryStringField="staff_id" Name="staff_payroll_id" Type="Int32" />
                    <asp:Parameter Name="service_id_int" Type="Int32" />
                    <asp:Parameter Name="start_date" Type="String" />
 
                </InsertParameters>
            </asp:SqlDataSource>
            <br />
            </div>
        </ItemTemplate>
 
    </asp:FormView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:IPTelephonyConnectionString %>"
        SelectCommand="SELECT staff_profile.staff_payroll_int, staff_profile.staff_forename_str, staff_profile.staff_surname_str, staff_profile.ddi_primary_number_str, staff_profile.ddi_secondary_number_str, team.team_name_str, phone_type.phone_type_name_str, branch.branch_name_str, branch.branch_id_int, team.team_id_int, phone_type.phone_type_id_int FROM phone_type INNER JOIN staff_profile INNER JOIN team ON staff_profile.team_id_int = team.team_id_int ON phone_type.phone_type_id_int = staff_profile.phone_type_id_int INNER JOIN branch ON team.branch_id_int = branch.branch_id_int WHERE (staff_profile.staff_payroll_int = @staff_payroll_int)" 
        DeleteCommand="DELETE FROM [staff_profile] WHERE [staff_payroll_int] = @staff_payroll_int" 
        InsertCommand="INSERT INTO [staff_profile] ([staff_payroll_int], [staff_forename_str], [staff_surname_str], [ddi_primary_number_str], [ddi_secondary_number_str], [phone_type_id_int], [team_id_int]) VALUES (@staff_payroll_int, @staff_forename_str, @staff_surname_str, @ddi_primary_number_str, @ddi_secondary_number_str, @phone_type_id_int, @team_id_int)" 
        UpdateCommand="UPDATE [staff_profile] SET [staff_forename_str] = @staff_forename_str, [staff_surname_str] = @staff_surname_str, [ddi_primary_number_str] = @ddi_primary_number_str, [ddi_secondary_number_str] = @ddi_secondary_number_str, [phone_type_id_int] = @phone_type_id_int, [team_id_int] = @team_id_int WHERE [staff_payroll_int] = @staff_payroll_int">
        <DeleteParameters>
            <asp:Parameter Name="staff_payroll_int" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="staff_forename_str" Type="String" />
            <asp:Parameter Name="staff_surname_str" Type="String" />
            <asp:Parameter Name="ddi_primary_number_str" Type="String" />
            <asp:Parameter Name="ddi_secondary_number_str" Type="String" />
            <asp:Parameter Name="phone_type_id_int" Type="Int32" />
            <asp:Parameter Name="team_id_int" Type="Int32" />
            <asp:Parameter Name="staff_payroll_int" Type="Int32" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="staff_payroll_int" Type="Int32" />
            <asp:Parameter Name="staff_forename_str" Type="String" />
            <asp:Parameter Name="staff_surname_str" Type="String" />
            <asp:Parameter Name="ddi_primary_number_str" Type="String" />
            <asp:Parameter Name="ddi_secondary_number_str" Type="String" />
            <asp:Parameter Name="phone_type_id_int" Type="Int32" />
            <asp:Parameter Name="team_id_int" Type="Int32" />
 
        </InsertParameters>
        <SelectParameters>
            <asp:SessionParameter Name="staff_payroll_int" SessionField="profile_id" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
    <br />
    <br />
    &nbsp;&nbsp;
    <br />
</asp:Content>

The error I get is:

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 65: Dim tmp As FormView = Me.FormView1.FindControl("formview3")
Line 66: Dim tmpgridview As GridView = tmp.FindControl("gridview2")
Line 67: CType(tmpgridview.Rows(rowid).FindControl("textbox3"), TextBox).Text = CType(tmpgridview.Rows(rowid).FindControl("Calendar2"), Calendar).SelectedDate
Line 68: End Sub
Line 69:

Any help on how I could get this to work would be great - thanks so much.

DS