Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在c中添加或删除新记录后刷新gridview#_C#_Asp.net_Gridview_.refresh - Fatal编程技术网

C# 在c中添加或删除新记录后刷新gridview#

C# 在c中添加或删除新记录后刷新gridview#,c#,asp.net,gridview,.refresh,C#,Asp.net,Gridview,.refresh,我的页面上有一个网格我需要刷新gridview添加和删除新记录,但不是吗 代码如下: 将行添加到GridView: private void AddClientToGrid() { int clientID = int.Parse(ddlClient.SelectedValue); int clientTypeID = int.Parse(ddlClientType.SelectedValue); ClientsAllCDO cli

我的页面上有一个网格我需要刷新gridview添加和删除新记录,但不是吗

代码如下:

将行添加到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 row from the database

GridView1.DataSource = SomeDataRetrievalMethod(); //retrieve the data from the database
GridView1.DataBind();

如果我从数据库中获取所有数据,是的,您的权利,但它不是这样工作的,首先数据插入网格,然后在更新时插入数据库新添加的数据可能会丢失。。。thx再次..顺便说一下,我说过rowdatabound正在启动,但数据没有刷新。。。为什么会有人知道
//delete row from the database

GridView1.DataSource = SomeDataRetrievalMethod(); //retrieve the data from the database
GridView1.DataBind();