GridView删除问题 [英] Problem with gridview Delete

查看:113
本文介绍了GridView删除问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
这是我用来绑定网格并单击时删除记录的代码. 单击删除按钮上的项目后,将从数据库中删除项目,但未使用正确的数据填充gridview(项目中也显示了已删除项目)我的代码是什么pbm ...请在htis中将我引出...所有内容提前帮助

Hi all,
This is the code i used to bind a grid and delete records on click..
on clicking the delete button items get delete from the datatbase but the gridview is not populate with correct data(Deleted item also seen in the items) what is the pbm with my code...please fuide me in htis...Tnaks for all help in advance

<asp:GridView ID="grdLocation" runat="server" AutoGenerateColumns="False" DataKeyNames="LocationID"

             OnRowCancelingEdit="grdLocation_RowCancelingEdit"

             OnRowDeleting="grdLocation_RowDeleting" OnRowEditing="grdLocation_RowEditing" 

             OnRowUpdating="grdLocation_RowUpdating" Visible="False" 

                    onrowdatabound="grdLocation_RowDataBound1">
                <columns>
                <asp:BoundField DataField="LocationID" HeaderText="Category ID" Visible="False" />
                <asp:BoundField DataField="LocationName" HeaderText="Category Name" />
                <asp:CommandField HeaderText="Edit-Update" ShowEditButton="True" />
                <asp:CommandField HeaderText="Delete" ShowDeleteButton="True" />
                </columns>





public void bindgrdLocation()
       {
           grdLocation.DataSource = (new Locations()).GetAllLocations();
           grdLocation.DataBind();
           if (grdLocation.Rows.Count > 0)
           {
               grdLocation.Visible = true;
               lblMessage.Visible = false;
           }
           else
           {
               grdLocation.Visible = false;
               lblMessage.Visible = true;
               lblMessage.Text = "No records Found";
           }
       }

 protected void grdLocation_RowDeleting(object sender, GridViewDeleteEventArgs e)
       {
           Locations location = new Locations();
           location.LocationID = Convert.ToInt32(grdLocation.DataKeys[e.RowIndex].Value.ToString());
           location.Delete();
           bindgrdLocation();

       }

推荐答案



在grdLocation_RowDeleting()事件上执行删除操作后,再次调用网格绑定方法"bindgrdLocation"来绑定网格
Hi,

call the grid bind method "bindgrdLocation" again to bind the grid after the delete operation is performed on grdLocation_RowDeleting() event


您是否传递了要删除的行的索引?

Gv1.Deleterow(e.RowIndex);
Gvi.DataBind();
Are you passing the index of the row to be deleted??

Gv1.Deleterow(e.RowIndex);
Gvi.DataBind();


这篇关于GridView删除问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆