刷新GridView控件在C#中添加或删除新的记录后, [英] refresh gridview after adding or deleting new record in c#
本文介绍了刷新GridView控件在C#中添加或删除新的记录后,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的网格我的网页上,我需要刷新GridView控件添加和删除新的记录,但它不是?
i've a grid on my page i need to refresh gridview add and delete new record but its not?
这里是code:
添加行GridView的:
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();
}
删除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...
推荐答案
您需要将网格重新绑定到数据源:
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();
这篇关于刷新GridView控件在C#中添加或删除新的记录后,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文