Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8266227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:04:55+00:00 2026-06-08T05:04:55+00:00

I have a Gridview that allows user to edit and delete the records. I

  • 0

I have a Gridview that allows user to edit and delete the records. I am using .net 3.5 using C#.

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.

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

Here is my 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");
        }
    }
}

markup code is:

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

The error is on this line: txtactsta.Attributes.Add("ReadOnly", "true");:

object reference no set to an instance of object

How can I fix this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T05:04:57+00:00Added an answer on June 8, 2026 at 5:04 am

    Doesn’t gdScheduleNew_RowDataBound get called for every row in your gridview? txtactualstartDate and txtactualendDate only exist on edit rows, they do not exist on non editing rows.

    Try this:

    if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowState == DataControlRowState.Edit)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a gridview that is bound to a datasource (Windows Forms, VB.NET). One
I have a gridview that contains user info and one of the columns is
I currently have an ASP.NET GridView that displays a few columns to the user
I have a ASP.NET GridView that uses template columns and user controls to allow
Does .NET have some type of built in function that allows filtering on Gridviews?
I have a gridview that shows an image as part of one of its
I have a gridview that displays items details, I added two template fields one
I have a delete button in each row of GridView (component ASP.NET). I want
I have GridView that allows select. It takes data from EntityDataSource . How do
I have a program that allows the user to use a few dropdowns to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.