4

i've a grid on my page i need to refresh gridview add and delete new record but its not?

here is the code:

Add Row To GridView:

    private void AddClientToGrid()
    {
        int clientID = int.Parse(ddlClient.SelectedValue);
        int clientTypeID = int.Parse(ddlClientType.SelectedValue);
        ClientsAllCDO client = new ClientsBL().ClientsAllSelectByIDAndClientTypeID(clientID, clientTypeID);
        List<ClientsAllCDO> clientList = new List<ClientsAllCDO>();
        clientList = GetClientsFromGrid();
        clientList.Add(client);
        gvClient.DataSource = clientList;
        gvClient.DataBind();
    }

Delete Code:

    protected void btnDeleteClient_Click(object sender, EventArgs e)
    {
        LinkButton btnDeleteClient = sender as LinkButton;
        int rowIndex = int.Parse(btnDeleteClient.Attributes["RowIndex"]);
        if (Request.QueryString["BailiffID"] == null)
        {
            gvClient.DeleteRow(rowIndex);
        }
        else
        {
            int bailiffID = int.Parse(FormCrypto.Decrypt(Request.QueryString["BailiffID"]));
            GridViewRow gvRow = gvClient.Rows[rowIndex];
            int clientTypeID = int.Parse(((Label)gvRow.FindControl("lblClientTypeID")).Text);
            int clientID = int.Parse(((Label)gvRow.FindControl("lblClientID")).Text);
            gvClient.DeleteRow(rowIndex);
            new BailiffClientsBL().BailiffClientDelete(clientID, bailiffID, clientTypeID);
        }         
    }

Thanks alot...

serim urhan
  • 139
  • 2
  • 10
  • 21

1 Answers1

4

You need to rebind the grid to the datasource:

//delete row from the database

GridView1.DataSource = SomeDataRetrievalMethod(); //retrieve the data from the database
GridView1.DataBind();
James Johnson
  • 45,496
  • 8
  • 73
  • 110
  • if i get all datas from db yes your right but its not working this way first datas inserting grid then inserting db on update new added data can be lost... thx again.. – serim urhan Sep 14 '11 at 09:44
  • by the way i have say rowdatabound is firing but data is not refreshing... what is the reason is there anyone knows – serim urhan Sep 14 '11 at 09:46