Gridview edit mode for more that one row
<p>I have a Gridview that allows user to edit and delete the records. I am using .net 3.5 using C#.</p>

<p>When I have just one record my edit command is working fine  but problem comes when there are more that 1 record in my gridview. </p>

<p>In this case while binding the controls it it is unable to find the controls the second time and thus throws the error.</p>

<p>code behind is - </p>

<pre><code>     protected void gdScheduleNew_RowDataBound(object sender, GridViewRowEventArgs e)
            {
if (e.Row.RowType == DataControlRowType.DataRow)
            {
    if (ViewState["Updating"].Equals(true))
                    {
                        TextBox txtactsta = (TextBox)e.Row.FindControl("txtactualstartDate");
                        TextBox txtactend = (TextBox)e.Row.FindControl("txtactualendDate");
                        LinkButton lnkUpdate = (LinkButton)e.Row.FindControl("lnkUpdate");
                        txtactsta.Attributes.Add("ReadOnly", "true");
                        txtactend.Attributes.Add("ReadOnly", "true");
                    }
}
</code></pre>

<p>markup code is -</p>

<pre><code>&lt;asp:GridView ID="gdScheduleNew" runat="server" Width="100%" SelectedIndex="0"
                        CellPadding="4" AutoGenerateColumns="False" ForeColor="#333333" Height="100px"
                        OnRowDataBound="gdScheduleNew_RowDataBound" onrowediting="gdSchedule_RowEditing"&gt;
    &lt;FooterStyle Font-Bold="True" ForeColor="White" /&gt;
    &lt;RowStyle BackColor="#F7F6F3" ForeColor="#333333" /&gt;
    &lt;Columns&gt;
        &lt;asp:TemplateField HeaderText="Planned Efforts"&gt;
        &lt;ItemTemplate&gt;
        &lt;asp:Label ID="lblscheduleid" runat="server" Text='&lt;%# Bind("scheduleid") %&gt;' 
                                                    Visible="false"&gt;&lt;/asp:Label&gt;
        &lt;asp:Label ID="lblPlannedEffort" runat="server" Text='&lt;%# Bind("sepcet") %&gt;'&gt;&lt;/asp:Label&gt;
        &lt;/ItemTemplate&gt;
        &lt;EditItemTemplate&gt;
        &lt;asp:Label ID="lblscheduleid" runat="server" Text='&lt;%# Bind("scheduleid") %&gt;' 
        Visible="false"&gt;&lt;/asp:Label&gt;
                &lt;asp:TextBox ID="txtsepcet" runat="server" Text='&lt;%# Bind("sepcet") %&gt;' 
                    Width="88px"&gt;&lt;/asp:TextBox&gt;
            &lt;/EditItemTemplate&gt;
            &lt;FooterTemplate&gt;
                &lt;asp:TextBox ID="ftxtsepcet" runat="server" Width="88px"&gt;&lt;/asp:TextBox&gt;
            &lt;/FooterTemplate&gt;
        &lt;/asp:TemplateField&gt;
        &lt;asp:TemplateField HeaderText="Actual Efforts"&gt;
            &lt;ItemTemplate&gt;
                &lt;asp:Label ID="lblActualEffort" runat="server" 
                    Text='&lt;%# Bind("actualeffort") %&gt;'&gt;&lt;/asp:Label&gt;
            &lt;/ItemTemplate&gt;
                &lt;EditItemTemplate&gt;
                &lt;asp:TextBox ID="txtactualeffort" runat="server" 
                        Text='&lt;%# Bind("actualeffort") %&gt;' Width="88px"&gt;&lt;/asp:TextBox&gt;
            &lt;/EditItemTemplate&gt;
            &lt;FooterTemplate&gt;
                &lt;asp:TextBox ID="ftxtactualeffort" runat="server" Width="88px"&gt;&lt;/asp:TextBox&gt;
            &lt;/FooterTemplate&gt;
        &lt;/asp:TemplateField&gt;
        &lt;asp:TemplateField HeaderText="Planned Start Date"&gt;
            &lt;ItemTemplate&gt;
                &lt;asp:Label ID="lblPlannedStart" runat="server" 
                    Text='&lt;%# Bind("plannedstartDate") %&gt;'&gt;&lt;/asp:Label&gt;
            &lt;/ItemTemplate&gt;
                &lt;EditItemTemplate&gt;
                &lt;asp:TextBox ID="txtplannedstartDate" runat="server" 
                        Text='&lt;%# Bind("plannedstartDate") %&gt;' class="dateclass" Width="88px"&gt;&lt;/asp:TextBox&gt;
            &lt;/EditItemTemplate&gt;
            &lt;FooterTemplate&gt;
                &lt;asp:TextBox ID="ftxtplannedstartDate" runat="server" class="dateclass" 
                    Width="88px"&gt;&lt;/asp:TextBox&gt;
            &lt;/FooterTemplate&gt;
        &lt;/asp:TemplateField&gt;
        &lt;asp:TemplateField HeaderText="Planned End Date"&gt;
            &lt;ItemTemplate&gt;
                &lt;asp:Label ID="lblPlannedEnd0" runat="server" 
                    Text='&lt;%# Bind("plannedendDate") %&gt;'&gt;&lt;/asp:Label&gt;
            &lt;/ItemTemplate&gt;
                &lt;EditItemTemplate&gt;
                &lt;asp:TextBox ID="txtplannedendDate" runat="server" 
                        Text='&lt;%# Bind("plannedendDate") %&gt;' class="dateclass" Width="88px"&gt;&lt;/asp:TextBox&gt;
            &lt;/EditItemTemplate&gt;
            &lt;FooterTemplate&gt;
                &lt;asp:TextBox ID="ftxtplannedendDate" runat="server" class="dateclass" 
                    Width="88px"&gt;&lt;/asp:TextBox&gt;
            &lt;/FooterTemplate&gt;
        &lt;/asp:TemplateField&gt;
        &lt;asp:TemplateField HeaderText="Actual Start Date"&gt;
            &lt;ItemTemplate&gt;
                &lt;asp:Label ID="lblActualStart" runat="server" 
                    Text='&lt;%# Bind("actualstartDate") %&gt;'&gt;&lt;/asp:Label&gt;
            &lt;/ItemTemplate&gt;
                &lt;EditItemTemplate&gt;
                &lt;asp:TextBox ID="txtactualstartDate" runat="server" 
                        Text='&lt;%# Bind("actualstartDate") %&gt;' class="dateclass" Width="88px"&gt;&lt;/asp:TextBox&gt;
            &lt;/EditItemTemplate&gt;
            &lt;FooterTemplate&gt;
                &lt;asp:TextBox ID="ftxtactualstartDate" runat="server" class="dateclass" 
                    Width="88px"&gt;&lt;/asp:TextBox&gt;
            &lt;/FooterTemplate&gt;
        &lt;/asp:TemplateField&gt;
        &lt;asp:TemplateField HeaderText="Actual End Date"&gt;
            &lt;ItemTemplate&gt;
                &lt;asp:Label ID="lblActualEnd" runat="server" 
                    Text='&lt;%# Bind("actualendDate") %&gt;'&gt;&lt;/asp:Label&gt;
            &lt;/ItemTemplate&gt;
                &lt;EditItemTemplate&gt;
                &lt;asp:TextBox ID="txtactualendDate" runat="server" 
                        Text='&lt;%# Bind("actualendDate") %&gt;' class="dateclass" Width="88px"&gt;&lt;/asp:TextBox&gt;
            &lt;/EditItemTemplate&gt;
            &lt;FooterTemplate&gt;
                &lt;asp:TextBox ID="ftxtactualendDate" runat="server" class="dateclass" 
                    Width="88px"&gt;&lt;/asp:TextBox&gt;
            &lt;/FooterTemplate&gt;
        &lt;/asp:TemplateField&gt;
        &lt;asp:TemplateField HeaderText="Member Name"&gt;
            &lt;ItemTemplate&gt;
                &lt;asp:Label ID="lblMember" runat="server" Text='&lt;%# Bind("membername") %&gt;'&gt;&lt;/asp:Label&gt;
            &lt;/ItemTemplate&gt;
                &lt;EditItemTemplate&gt;
                    &lt;asp:DropDownList ID="ddlmem" runat="server" DataTextField="MemberName" DataValueField="MemberID"&gt;
                    &lt;/asp:DropDownList&gt;
            &lt;/EditItemTemplate&gt;
            &lt;FooterTemplate&gt;
                    &lt;asp:DropDownList ID="fddlmem" runat="server" DataTextField="MemberName" DataValueField="MemberID"&gt;
                    &lt;/asp:DropDownList&gt;
            &lt;/FooterTemplate&gt;
        &lt;/asp:TemplateField&gt;
        &lt;asp:TemplateField HeaderText="Status"&gt;
            &lt;ItemTemplate&gt;
                &lt;asp:Label ID="lblStatus" runat="server" Text='&lt;%# Bind("status") %&gt;'&gt;&lt;/asp:Label&gt;
            &lt;/ItemTemplate&gt;
        &lt;/asp:TemplateField&gt;
        &lt;asp:TemplateField HeaderText="Edit" ShowHeader="False"&gt; 
        &lt;EditItemTemplate&gt; 
            &lt;asp:LinkButton ID="lnkUpdate" runat="server" CausesValidation="True" CommandName="Update" Text="Update"&gt;&lt;/asp:LinkButton&gt; 
            &lt;br /&gt;
            &lt;asp:LinkButton ID="LnkCancel" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"&gt;&lt;/asp:LinkButton&gt; 
        &lt;/EditItemTemplate&gt;     
        &lt;FooterTemplate&gt; 
            &lt;asp:LinkButton ID="lnkAddnew" runat="server" CausesValidation="true" 
                CommandName="AddNew" Text="Submit"&gt;&lt;/asp:LinkButton&gt; 
        &lt;/FooterTemplate&gt; 
        &lt;ItemTemplate&gt; 
                &lt;asp:LinkButton ID="lnkEdit" runat="server" CausesValidation="False" 
                    CommandName="Edit" Text="Edit"&gt;&lt;/asp:LinkButton&gt; 
        &lt;/ItemTemplate&gt; 
        &lt;/asp:TemplateField&gt; 
    &lt;/Columns&gt;
&lt;/asp:GridView&gt;
</code></pre>

<p>txtactsta.Attributes.Add("ReadOnly", "true");
 this line throws error that </p>

<blockquote>
  <p><code>object reference no set to an instance of object</code></p>
</blockquote>
