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 8917875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:36:06+00:00 2026-06-15T05:36:06+00:00

So I have this problem with one of my pages, which basically lists out

  • 0

So I have this problem with one of my pages, which basically lists out a bunch of comments for a specified student. The comments are supposed to be editable, but I’m having a problem with getting the contents of a row (so I can display the comment content in a TextBox and allow for edits).

The issue is that whenever I access the GridViewRow from the GridView like such:
this.CommentList.Rows[e.NewEditIndex]
It is returning a collection of cells, but whenever I try access the a cell like so: row.Cells[0].Text (where row is the selected GridViewRow object) it doesn’t return any values.

Here is my .aspx code:

<asp:GridView ID="CommentList" runat="server" AutoGenerateColumns="False" CellPadding="5"
    ShowHeader="false" Width="100%" DataKeyNames="CommentId" OnRowDeleting="CommentList_RowDeleting"
    OnRowCancelingEdit="CommentList_RowCancelingEdit" OnRowEditing="CommentList_RowEditing">
    <Columns>
        <asp:TemplateField HeaderText="Student ID">
            <ItemTemplate>
                <b>Author:</b>
                <%# ((Comment)Container.DataItem).Author.Name %>
                <br />
                <b>Date:</b>
                <%# ((Comment)Container.DataItem).Created %>
                <hr style="border-top: solid 1px black" />
                <div style="text-align: center;">
                    <asp:Panel ID="OptionsPanel" runat="server">
                        <asp:LinkButton ID="DeleteLinkButton" CommandName="Delete" runat="server" OnClientClick="return confirm('Are you sure you want to delete this comment?');">Delete</asp:LinkButton>
                        |
                        <asp:LinkButton ID="EditLinkButton" runat="server" CommandName="Edit">Edit</asp:LinkButton>
                    </asp:Panel>
                    <asp:Panel ID="EditOptionsPanel" runat="server" Visible="false">
                        <asp:LinkButton ID="CancelEditLinkButton" runat="server" CommandName="Cancel">Cancel</asp:LinkButton>
                    </asp:Panel>
                </div>
            </ItemTemplate>
            <ItemStyle CssClass="topLeftJustify" Width="200px" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Name">
            <ItemTemplate>
                <asp:Panel ID="ViewCommentPanel" runat="server">
                    <%# ((Comment)Container.DataItem).Content%>
                </asp:Panel>
                <asp:Panel ID="EditCommentPanel" runat="server" Visible="false">
                    <asp:TextBox ID="Comment" runat="server" CssClass="textEntry" TextMode="MultiLine"
                        Width="100%" Height="100px"></asp:TextBox>
                </asp:Panel>
            </ItemTemplate>
            <ItemStyle CssClass="topLeftJustify" />
        </asp:TemplateField>
    </Columns>
</asp:GridView>

Here is my .aspx.cs code (that relates to the code above):

    protected void CommentList_RowEditing(object sender, GridViewEditEventArgs e)
    {
        try
        {
            GridViewRow row = this.CommentList.Rows[e.NewEditIndex];
            ((Panel)row.FindControl("OptionsPanel")).Visible = false;
            ((Panel)row.FindControl("EditOptionsPanel")).Visible = true;
            ((Panel)row.FindControl("ViewCommentPanel")).Visible = false;
            ((Panel)row.FindControl("EditCommentPanel")).Visible = true;

            // problem is with this line. it doesn't show the contents of the "comment"
            ((TextBox)row.FindControl("Comment")).Text = row.Cells[0].Text;
        }
        catch (Exception ex)
        {
            this.Messages.ChangeMessage(ex.Message, MessageType.Error);
        }
    }
  • 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-15T05:36:07+00:00Added an answer on June 15, 2026 at 5:36 am

    When you use a TemplateField you cannot use e.Row.Cells[index].Text to access a control text of the cell. I would simply add a Label to the panel.

    But you can also try it this way:

    Panel ViewCommentPanel = (Panel) e.Row.FindControl("ViewCommentPanel");
    LiteralControl objPanelText = ViewCommentPanel.Controls[0] as LiteralControl;
    TextBox Comment = (TextBox) row.FindControl("Comment");
    Comment.Text = objPanelText.Text;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, this is a weird problem I'm having. I have two pages, which are
I really have problem with this one. So I have a jar with a
So i'm having this problem. I have two tables (Oracle), one is called Destination
My problem is this one, I am using Sharepoint 2010, I have a form
This is my problem, I have one textbox, one button and one label. Everything
This is a thought problem, and one I have been wrestling with for about
I have a problem with my WCF Data Service, and this one is just
I'm training code problems like UvA and I have this one in which I
This is an annoying problem I am having with Twisted.web. Basically, I have a
Basically my problem is this: I have a CSV excel file with info on

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.