当绑定到一个DataTable的GridView编辑 [英] GridView edit when bound to a Datatable

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

问题描述

我创建了一个网站,我们的客户可以从我们这里直接订购部件。我有一个数据表的设置和当用户点击一个按钮,它增加了订单的快速细节到一个GridView。在GridView,我有编辑和删除按钮启用。删除功能工作正常,但是当您尝试编辑的信息,它不会与新的信息改变gridview的。这是我到目前为止有:

I am creating a website where our customers can order parts directly from us. I have a datatable setup and when users click a button it adds a quick detail of the order to a gridview. In the gridview, I have the edit and delete buttons enabled. the delete function works fine, however when you try to edit the information, it doesn't change the gridview with the new info. Here's what I have so far:

protected void griditems_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
  DataTable dt = (DataTable)Session["table"];
  foreach (DataRow dr in dt.Rows)
    {
        part = Convert.ToString(dr["Part"]);
        dr["Part"] = part;
        dr["Quantity"] = qty;
        dr["Ship-To"] = shipto;
    }

    griditems.EditIndex = -1;
    BindData();
}

尝试这种在

,它显示在GridView回到与原来的输入值。我也试过这种(不工作,并得到一个错误,指出有位置0无行:

when trying this, it displays the gridview back with the original input values. I have also tried this (not working and get an error that says "There is no row at position 0":

DataTable dt = (DataTable)Session["table"];
GridViewRow row = griditems.Rows[e.RowIndex];
dt.Rows[row.DataItemIndex]["Part"] = ((TextBox)(row.Cells[1].Controls[0])).Text;
dt.Rows[row.DataItemIndex]["Quantity"] = ((TextBox)(row.Cells[2].Controls[0])).Text;
dt.Rows[row.DataItemIndex]["Ship-To"] = ((CheckBox)(row.Cells[3].Controls[0])).Checked;

griditems.EditIndex = -1;
BindData();

我失去了一个 EditItemTemplate中在aspx文件,还是我只是做了 RowUpdating 都错了?

Am I missing an EditItemTemplate in the aspx file, or am I just doing the RowUpdating all wrong?

推荐答案

您可能需要退一步一点,首先检查了,你怎么可以创建,更新,删除和网格视图读取。此外,您可能想检查这个帖子

You probably need to step back a bit and first check out how you could do create, update, delete and read with a grid view. Also, you may wanna check this post.

这篇关于当绑定到一个DataTable的GridView编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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