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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:13:03+00:00 2026-05-23T15:13:03+00:00

I have a gridview that binds its rows from an objects method: public DataSet

  • 0

I have a gridview that binds its rows from an objects method:

public DataSet GetObjects()
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
var source = from p in CommentsList
select new { p.CommentID, p.Img, p.Name, p.Comment };

dt.Columns.Add("CommentsID");
dt.Columns.Add("Img");
dt.Columns.Add("Name");
dt.Columns.Add("Comment");

foreach (var item in source)
{



    DataRow userDetailsRow=dt.NewRow();
    userDetailsRow["Img"] = item.Img;
    userDetailsRow["Name"] = item.Name;

    DataRow commentsID = dt.NewRow();
    userDetailsRow["CommentsID"] = item.CommentID;

    DataRow comments = dt.NewRow();
    userDetailsRow["Comment"] = item.Comment;
    dt.Rows.Add(userDetailsRow);
    //dt.Rows.Add(comments);
}
ds.Tables.Add(dt);
return ds;

}
My delete method. Should receive the commentsID to delete it from the database and then rebind the Gridview.. But how? do i pass the CommentsID from the gridview to this method
public void RemoveComment(int CommentsID)
{
}

GridViews Two templates:

 <Columns>
      <asp:TemplateField>
                        <ItemTemplate>
                            <asp:Label ID="lblMessage" runat="server"  Text='<%# Bind("Comment") %>'></asp:Label>
                        </ItemTemplate>
       </asp:TemplateField>

           <asp:TemplateField>
                        <ItemTemplate>
                            <asp:Image ID="imgName" runat="server"  imageUrl='<%# Bind("Img") %>'></asp:Image><br />
                            <asp:Hyperlink ID="hyperLink" runat="server"  Text='<%# Bind("Name") %>' ></asp:Hyperlink>
                        </ItemTemplate>
       </asp:TemplateField>
   </Columns>

Now, I want to delete a row, how do I do that? I know that DataKeyNames exist..but how do I set the commentsID as my dataKeyNames, and how do i delete a record?

  • 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-05-23T15:13:03+00:00Added an answer on May 23, 2026 at 3:13 pm

    You can specify the Delete method to the objectDataSource and it will be very simple…e.g.

     <asp:ObjectDataSource ID="ods" runat="server" DeleteMethod="RemoveComment" SelectMethod="GetCityByStateID" TypeName="">
            <DeleteParameters>
                <asp:Parameter Name="CommentsID" Type="Int32" />
             </DeleteParameters>
              <SelectParameters>
              </SelectParameters>
      </asp:ObjectDataSource>
    

    Whenever the Gridview Delete button is hit this will automatically fire this method and delete the record.

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

Sidebar

Related Questions

I have a GridView to which I bind a dataTable that I manually created.
I have a gridview that shows an image as part of one of its
I have a datalist that contains a gridview inside its itemtemplate. on the item-data_bound
I have a gridview that is bind to the datatable. how to programmaticaly change
I have a bound field in my Gridview which is getting its value from
I'm creating a dynamic GridView from a DataTable that is returned from a stored
I have a GridView control on my ASP.NET page that binds to result set
I have a GridView that (in one particular instance) would contain about 5000 rows,
I have data that gets displayed in gridview. If I'm pulling it from one
I have a GridView that I would like to bind to an ObjectDataSource. I

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.