0

什么是直接在 Web 表单中更新和保存网格视图数据的代码。这是我拥有的代码。帮我删除记录和更新记录。

   protected void CancelRecord(object sender, GridViewCancelEditEventArgs e)
{
    gridRegistrationTableDetails.EditIndex = -1;
    BindData();
}
protected void EditRecord(object sender, GridViewEditEventArgs e)
{
    gridRegistrationTableDetails.EditIndex = e.NewEditIndex;
    BindData();
}
protected void UpdateRecord(object sender, GridViewUpdateEventArgs e)
{

}
protected void DeleteRecord(object sender, GridViewDeleteEventArgs e)
{}

我需要编辑四列 Emp name,Emp address,emp dept,emp mail.emp ID 是主键。请帮我解决这个问题..

4

2 回答 2

2

如果您正在使用数据库,则为更新和删除创建函数 例如: Public void Update(DataClass dataclass){...} public void Delete(int Id){...}

在您的 apsx 页面中编写以下代码

                <Columns>
                    <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                </Columns>

            </asp:GridView>
            <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
                DataObjectTypeName="DataClass" DeleteMethod="Delete" 
                TypeName="YourServiceClass" UpdateMethod="Update">
                <DeleteParameters>
                    <asp:Parameter Name="id" Type="Int32" />
                </DeleteParameters>
            </asp:ObjectDataSource>
于 2012-08-03T11:13:33.857 回答
0

将此代码放在 gridview Rowdeleting 事件中

GridViewRow row = (GridViewRow)gv_Type.Rows[e.RowIndex];
d.con_Open();
SqlCommand cmd = new SqlCommand("Delete from tbl_Category where Catno=" + Convert.ToInt32(gv_Type.Rows[e.RowIndex].Cells[1].Text) + "", d.con);
cmd.ExecuteNonQuery();
d.con_Close();
于 2013-02-28T12:26:12.523 回答