问题如题,代码在下面protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            try
            {
                DataTable taskTable = new DataTable("TaskItem");                // Create the columns.
                taskTable.Columns.Add("图号", typeof(string));
                taskTable.Columns.Add("工序号", typeof(int));
                taskTable.Columns.Add("工序名称", typeof(string));
                taskTable.Columns.Add("简工艺", typeof(string));
                taskTable.Columns.Add("准备工时,分钟", typeof(float));
                taskTable.Columns.Add("单件工时,分钟", typeof(float));
                taskTable.Columns.Add("录入人", typeof(string));
                taskTable.Columns.Add("录入时间", typeof(string));
                taskTable.Columns.Add("审核人", typeof(string));
                taskTable.Columns.Add("审核时间", typeof(string));                //Persist the table in the Session object.
                //Session["TaskTable"] = taskTable;
                Session.Add("TaskTable", taskTable);
                // 将表添加到DataView对象中
                DataView view = new DataView((DataTable)Session["TaskTable"]);                // 指定GridView的数据源,并绑定数据
                TaskGridView.DataSource = view;
                TaskGridView.DataBind();
            }
            catch (Exception ex) 
            {
               
            }
        }
    }
protected void TaskGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {        if (Session["TaskTable"] != null)
        {
            //Retrieve the table from the session object.
            DataTable dt = (DataTable)Session["TaskTable"];            //Update the values.
            GridViewRow row = TaskGridView.Rows[e.RowIndex];            dt.Rows[row.DataItemIndex]["图号"] = TaskGridView.Rows[e.RowIndex].Cells[1].Text;
            dt.Rows[row.DataItemIndex]["工序号"] = int.Parse(TaskGridView.Rows[e.RowIndex].Cells[2].Text);
            dt.Rows[row.DataItemIndex]["工序名称"] = ((TextBox)TaskGridView.Rows[e.RowIndex].Cells[3].Controls[0]).Text;
            dt.Rows[row.DataItemIndex]["简工艺"] = ((TextBox)TaskGridView.Rows[e.RowIndex].Cells[4].Controls[0]).Text;
            dt.Rows[row.DataItemIndex]["准备工时,分钟"] = ((TextBox)TaskGridView.Rows[e.RowIndex].Cells[5].Controls[0]).Text;
            dt.Rows[row.DataItemIndex]["单件工时,分钟"] = ((TextBox)TaskGridView.Rows[e.RowIndex].Cells[6].Controls[0]).Text;
            dt.Rows[row.DataItemIndex]["录入人"] = Request.ServerVariables["LOGON_USER"].ToString().Substring(4);
            dt.Rows[row.DataItemIndex]["录入时间"] = DateTime.Now;            //Reset the edit index.
            TaskGridView.EditIndex = -1;
            
            //Bind data to the GridView control.
            BindData();
        }
        else
        {
            Response.Write("session is null");
        }
    }

解决方案 »

  1.   

    更新后重新绑定数据源BindData()这么怎么写的
      

  2.   

        private void BindData()
        {
            // 将表添加到DataView对象中
            DataView view = new DataView((DataTable)Session["TaskTable"]);        // 指定GridView的数据源,并绑定数据
            TaskGridView.DataSource = view;
            TaskGridView.DataBind();
        }
      

  3.   

    估计你更新后没将table 写打 Session中 
    Session.Add("TaskTable", taskTable);
    而绑定时 你是获取Session中的值
      

  4.   

    TaskGridView_RowUpdating
    在这个方法设置个断点调试下主要注意 e.RowIndex的值,进入BindData()方法//
    在BindData(); 语句之前,是不是要 Session["TaskTable"] = dt;
    //你的BindData方法是从session中取datatable的吧
      

  5.   

    TaskGridView_RowUpdating中
    更改:
              TaskGridView.EditIndex = -1;
                Session["TaskTable"] = dt;
                //Bind data to the GridView control.
                BindData();
      

  6.   

    Peter200694013 
    六楼的方式试过了,还是不行
      

  7.   


    protected void TaskGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {        if (Session["TaskTable"] != null)
            {
                //Retrieve the table from the session object.
                DataTable dt = (DataTable)Session["TaskTable"];            //Update the values.
                GridViewRow row = TaskGridView.Rows[e.RowIndex];            dt.Rows[row.DataItemIndex]["图号"] = TaskGridView.Rows[e.RowIndex].Cells[1].Text;
                dt.Rows[row.DataItemIndex]["工序号"] = int.Parse(TaskGridView.Rows[e.RowIndex].Cells[2].Text);
                dt.Rows[row.DataItemIndex]["工序名称"] = ((TextBox)TaskGridView.Rows[e.RowIndex].Cells[3].Controls[0]).Text;
                dt.Rows[row.DataItemIndex]["简工艺"] = ((TextBox)TaskGridView.Rows[e.RowIndex].Cells[4].Controls[0]).Text;
                dt.Rows[row.DataItemIndex]["准备工时,分钟"] = ((TextBox)TaskGridView.Rows[e.RowIndex].Cells[5].Controls[0]).Text;
                dt.Rows[row.DataItemIndex]["单件工时,分钟"] = ((TextBox)TaskGridView.Rows[e.RowIndex].Cells[6].Controls[0]).Text;
                dt.Rows[row.DataItemIndex]["录入人"] = Request.ServerVariables["LOGON_USER"].ToString().Substring(4);
                dt.Rows[row.DataItemIndex]["录入时间"] = DateTime.Now;            //Reset the edit index.
                TaskGridView.EditIndex = -1;
                
                //Bind data to the GridView control.
              Session["TaskTable"]= dt ;            BindData();
            }
            else
            {
                Response.Write("session is null");
            }
        }
      

  8.   


    不是,获取到的值是原来的值,不是TextBox中修改之后的值
      

  9.   

    断点调试时,dt中对应的row改变了么?
      

  10.   

    Cache,session保存datatable
    <ItemTemplate> 
    <%# Eval("a") %> 
    </ItemTemplate> 
    <EditItemTemplate > 
    <asp:TextBox ID="TextBox1" runat="server" Text=' <%# Bind("a") %>'> </asp:TextBox> 
    </asp:TextBox>   protected void gv_RowUpdating(object sender, GridViewUpdateEventArgs e) 
            { 
                gv.EditIndex = e.RowIndex; 
                string str= ((TextBox)gv.Rows[e.RowIndex].FindControl("TextBox1")).Text.Trim(); 
              } 
      

  11.   


    我是这样弄的,你看下代码,应该怎么改啊?<td class="style14" colspan="6">
                    <asp:GridView ID="TaskGridView" runat="server" AllowPaging="True" Width="930px"  PageSize="25"  DataKeyNames="图号,工序号" 
                    AutoGenerateColumns="False" AutoGenerateEditButton="True" AutoGenerateDeleteButton="True" OnRowDeleting="TaskGridView_RowDeleting"
                    OnRowEditing="TaskGridView_RowEditing" OnRowCancelingEdit="TaskGridView_RowCancelingEdit" OnRowUpdating="TaskGridView_RowUpdating" 
                    OnRowCommand="TaskGridView_RowCommand" OnPageIndexChanging="TaskGridView_PageIndexChanging">
                        <HeaderStyle Height="30px" Font-Size="Small"/>
                        <RowStyle Height="30px" />
                        <Columns>
                            <asp:BoundField DataField="图号" HeaderText="图号" ReadOnly="True" SortExpression="图号" HeaderStyle-Font-Size="Small">
                                <ItemStyle width="120px" Wrap="True" Font-Size="Small"/>
                            </asp:BoundField>
                            <asp:BoundField DataField="工序号" HeaderText="工序号" ReadOnly="True" SortExpression="工序号" HeaderStyle-Font-Size="Small">
                                <ItemStyle width="40px" Font-Size="Small"/>
                            </asp:BoundField>
                            <asp:BoundField DataField="工序名称" HeaderText="工序名称" SortExpression="工序名称" HeaderStyle-Font-Size="Small">
                                <ItemStyle width="40px" Wrap="True" Font-Size="Small"/>
                                <ControlStyle Width="30px" />
                            </asp:BoundField>
                            <asp:BoundField DataField="简工艺" HeaderText="简工艺" SortExpression="简工艺" HeaderStyle-Font-Size="Small">
                                <ItemStyle width="210px" Font-Size="Small" Wrap="True" />
                                <ControlStyle Width="200px" />
                            </asp:BoundField>
                            <asp:BoundField DataField="准备工时,分钟" HeaderText="准备工时,分钟" SortExpression="准备工时,分钟" HeaderStyle-Font-Size="Small">
                                <ItemStyle width="60px" Font-Size="Small"/>
                                <ControlStyle Width="50px" />
                            </asp:BoundField>
                            <asp:BoundField DataField="单件工时,分钟" HeaderText="单件工时,分钟" SortExpression="单件工时,分钟" HeaderStyle-Font-Size="Small">
                                <ItemStyle width="60px" Font-Size="Small"/>
                                <ControlStyle Width="50px" />
                            </asp:BoundField>
                            <asp:BoundField DataField="录入人" HeaderText="录入人" SortExpression="录入人" ReadOnly="true" HeaderStyle-Font-Size="Small">
                                <ItemStyle width="45px" Font-Size="Small" />
                            </asp:BoundField>
                            <asp:BoundField DataField="录入时间" HeaderText="录入时间" SortExpression="录入时间" ReadOnly="true" HeaderStyle-Font-Size="Small">
                                <ItemStyle width="80px" Font-Size="Small"/>
                            </asp:BoundField>
                            <asp:BoundField DataField="审核人" HeaderText="审核人" SortExpression="审核人" ReadOnly="true" HeaderStyle-Font-Size="Small">
                                <ItemStyle width="45px" Font-Size="Small" />
                            </asp:BoundField>
                            <asp:BoundField DataField="审核时间" HeaderText="审核时间" SortExpression="审核时间" ReadOnly="true" HeaderStyle-Font-Size="Small">
                                <ItemStyle width="80px" Font-Size="Small" />
                            </asp:BoundField>
                            <asp:ButtonField ButtonType="Button" CommandName="审核" Text="审核" >
                                <ItemStyle width="30px" Height="30px"/>
                            </asp:ButtonField>
                        </Columns>
                    </asp:GridView>