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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:19:58+00:00 2026-06-05T02:19:58+00:00

I have a GridView set up: <asp:GridView id=GridView1 Runat=server AutoGenerateColumns=False OnRowCommand = GridView1_RowCommand EnableViewState=true>

  • 0

I have a GridView set up:

<asp:GridView id="GridView1" Runat="server" AutoGenerateColumns="False" OnRowCommand = "GridView1_RowCommand" EnableViewState="true">
   <Columns>
       <asp:TemplateField HeaderText="Delete" ItemStyle-HorizontalAlign="Center"> 
            <ItemTemplate><asp:Button runat="server" ID="Delete" ImageUrl="~/images/Close.gif" CommandName="DeleteRow" CommandArgument="<%# CType(Container,GridViewRow).RowIndex %>"/></ItemTemplate></asp:TemplateField>

       <asp:TemplateField HeaderText="Comment" ItemStyle-Width="175px">
            <ItemTemplate><textarea class="raTextBox" id="txtItemComment" rows="4" cols="30"></textarea></ItemTemplate></asp:TemplateField> 
   </Columns>   
</asp:GridView>

The RowCommand in code-behind is setup like:

Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs)
   If (e.CommandName = "DeleteRow") Then
     //do stuff here

The GridView is data bound on Page Load as follows:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  If Not IsPostBack Then
     Session("CalledModule") = "RCMT0021"
  Else
      With ViewState
           _intRepor = CInt(.Item("Report"))
      End With
  End If
     DataBind()   //Gridview Load
End Sub

My questions:

  1. The row command event is never fired. The page just goes into the ELSE (of Not is Postback) in Page_Load
  2. How can I keep track of what all is typed in the “Comments” column of each row (a TEXTAREA), and save the data to the database when a SAVE CHANGES (form) button is clicked?

Thanks!

UPDATE:
The Grid-View’s Databinding is as follows:

Public Sub DataBind()
Dim clsDatabase As New clsDatabase
Dim cmd As New OleDbCommand()
Try
 cmd.CommandText = "SELECT A, B FROM WHERE C = ? ORDER BY A"
   Dim report As New OleDbParameter("@Report", _intReportNumber)
   cmd.Parameters.Add(report)

   cmd.Connection = clsDatabase.Open_DB()
   Dim dReader As OleDbDataReader
   dReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)

   Dim dt As New DataTable
   dt.Columns.Add(New DataColumn("PictureURL", GetType(String)))
   dt.Columns.Add(New DataColumn("Seq", GetType(Int16)))
   dt.Columns.Add(New DataColumn("ReportNumber", GetType(String)))

   Do While (dReader.Read())
      Dim dr As DataRow = dt.NewRow()

      _strComments = dReader(0).ToString
      dr("Seq") = dReader.GetInt16(1)
      dr("PictureURL") = "GetImages.aspx?report=" + _intReportNumber.ToString + "&seq=" + dReader.GetInt16(1).ToString
      dr("ReportNumber") = _intReportNumber.ToString
      dt.Rows.Add(dr)
   Loop

   GridView1.DataSource = dt
   GridView1.DataBind()

  Catch err As Exception
 End Try
End Sub

enter image description here

So basically, the GridView has three visible columns – a comments field, a picture field, and a field with a delete button (image) to delete the picture (and comments, if any) from the database. The 4th column is a hidden one, keeping track of the the Image ID of the images. I didn’t include the picture and other columns for simplicity sake.

  • The user can add comments, and when he clicks a ‘SAVE CHANGES’ button, the corresponding comments should get saved for the picture.
  • The ‘SELECT IMAGE’ opens up a ModalDialogBox which enables the user to select the image. When closed, it causes a postback, and rebinds the gridview to display the image the user just selected. Therefore, I need the GridView to rebind on postback, or a way around this.
  • The delete imagebutton (in gridview) should delete the image and comments from the database.

Thanks again!

  • 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-05T02:20:00+00:00Added an answer on June 5, 2026 at 2:20 am

    try this structure…

    aspx page: (note textarea has runat="server")

    <body>
        <form runat="server">
        <asp:ScriptManager runat="server" />
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand"
                    EnableViewState="true" OnRowDataBound="GridView1_RowDataBound">
                    <Columns>
                        <asp:TemplateField HeaderText="Delete" ItemStyle-HorizontalAlign="Center">
                            <ItemTemplate>
                                <asp:Button runat="server" ID="Delete" Text="Delete" />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Comment" ItemStyle-Width="175px">
                            <ItemTemplate>
                                <textarea runat="server" class="raTextBox" id="txtItemComment" rows="4" cols="30"></textarea></ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
            </ContentTemplate>
        </asp:UpdatePanel>
        </form>
    </body>
    

    aspx.cs:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            BindGrid();
        }
    }
    
    protected void BindGrid()
    {
        var items = new List<string>();
        for (int i = 0; i < 10; i++)
        {
            items.Add(i + ";comment" + i.ToString());
        }
        GridView1.DataSource = items;
        GridView1.DataBind();
    }
    
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "DeleteRow")
        {
            var idx = Convert.ToInt32(e.CommandArgument);
            var cmt = GridView1.Rows[idx].FindControl("txtItemComment") as System.Web.UI.HtmlControls.HtmlTextArea;
            cmt.Value = DateTime.Now.ToString();
        }
    }
    
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            var item = e.Row.DataItem.ToString().Split(";".ToCharArray());
    
            var del = e.Row.FindControl("Delete") as Button;
            del.CommandName = "DeleteRow";
            del.CommandArgument = item[0];
    
            var cmt = e.Row.FindControl("txtItemComment") as System.Web.UI.HtmlControls.HtmlTextArea;
            cmt.Value = item[1];
        }
    }
    

    then clicked on 3 buttons

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I Have a and ASP.NET GridView which is set so <asp:GridView ID=GridView1 runat=server AutoGenerateColumns=False
I have a gridview with the alternatingRowStyle property set. <asp:GridView ID=GridView1 runat=server AutoGenerateColumns=False DataSourceID=SqlDataSource2
I have an ASP.Net GridView with properties like so: <asp:GridView ID=grdOrderEntry runat=server AutoGenerateColumns=false ShowFooter=True
The .aspx: <asp:GridView ID=gvFirst runat=server AutoGenerateColumns=false AllowPaging=true ondatabound=gvFirst_DataBound > <Columns> <asp:BoundField DataField=ID HeaderText=ProductID/> <asp:BoundField
I have a Datagrid which looks as under <asp:GridView ID=dgTask runat=server Width=100% AutoGenerateColumns=False> <Columns>
I want to provide custom paging in grid view. <asp:GridView ID=gvFirst runat=server AutoGenerateColumns=false AllowPaging=true
I have a asp:GridView with a HyperLinkField . It's DataNavigateUrlFormatString property is set to
I have an ASP.net GridView that spits out three columns of data: ( OrderNumber,
I have a GridView control on my ASP.NET page that binds to result set
I have a GridView which uses BoundField for columns. I am trying to set

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.