在c#中添加或删除新记录后刷新gridview
我的页面上有一个网格,我需要刷新 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();
}
删除代码:
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);
}
}
非常感谢...
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将网格重新绑定到数据源:
You need to rebind the grid to the datasource: