1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

problems deleting from gridview

Discussion in 'C#' started by dazi_behappy, Oct 25, 2006.

  1. #1
    Hi all,
    I have a datafunction that selects content from a database to be inserted into the gridview.

    I have another datafunction that will delete a row from the gridveiw. This datafunction required a parameter. The parameter is not saved into the gridview. This is where my problem begins.....

    Is there any way of getting the parameter required, saved somewhere, so that when i come to delete a row, i can get it into the function below:
    
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                //GET PARAMETER HERE...
            }
         }
    
    Code (markup):
    Im using an ObjectDataSource, which is configured to a business object. I have a data function selected for the SELECT and DELETE methods. The datafunction are not saved in the database, they are located within the App_Code folder.

    SELECT method - GetAll(int userid)
    DELETE method- Delete(int userid, intStockid)

    Therefore it is the function parameters that im having trouble getting into the DELETE method.

    I managed to get the parameter required for the select method using the following line of code in the page_load

    
    ObjectDataSource1.SelectParameters["UserID"].DefaultValue = userID.ToString();
    
    Code (markup):
    However, I cant seem to get the function parameters needed for the delete method when any of the delete buttons from the gridview are clicked.

    Idealy, i would like to have a hiddern field in the gridview that could hold the StockID. When the delete button is clicked, I could receive the StockID into the GridView1_RowCommand function, and manually delete the row required (by calling DataFunction.Delete(userid, StockID) inside the RowCommand function.

    Many thanks in advanced, this problem has been causing me no ends of trouble. Any help would be much appreciated
     
    dazi_behappy, Oct 25, 2006 IP
  2. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #2
    FindControl - DirectCast as hiddenfield or Whatever kind of control you want. That's all you need to know to modify any of the .NET controls

    or iterate through each item on page pre-render. iterate over each row, then findcontrols in the column of each row :)
     
    ccoonen, Nov 10, 2006 IP