问题如题,代码在下面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");
}
}
{
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");
}
}
解决方案 »
- 关于三层,数据库的视图如何使用。
- Web.config究竟是ASP.Net的配置文件还是IIS的配置文件
- 关于 SQL2005导出数据至 Excel 2007
- 网页里怎样显示.doc文件的内容???来者有分!!!
- 如何把一个Sql语句传给下一个页面?
- 谁知道关于ASP.NET的漏洞方面的一些知识!!!
- 路径问题
- 老板让我2周从ASP转到asp.net 各位给支个招!!!!!!!!! 顺便散个分!!!!!!!!!
- 怎样在本机上建立一个内部小网站?
- <%@ Page language="c#" Codebehind="admin.aspx.cs" AutoEventWireup="false" Inherits="finace.admin" %>
- 各位高手你们都用什么记录日志信息?希望有现成的简单例子,我好研究研究
- 验证控件与label控件设置的问题
{
// 将表添加到DataView对象中
DataView view = new DataView((DataTable)Session["TaskTable"]); // 指定GridView的数据源,并绑定数据
TaskGridView.DataSource = view;
TaskGridView.DataBind();
}
Session.Add("TaskTable", taskTable);
而绑定时 你是获取Session中的值
在这个方法设置个断点调试下主要注意 e.RowIndex的值,进入BindData()方法//
在BindData(); 语句之前,是不是要 Session["TaskTable"] = dt;
//你的BindData方法是从session中取datatable的吧
更改:
TaskGridView.EditIndex = -1;
Session["TaskTable"] = dt;
//Bind data to the GridView control.
BindData();
六楼的方式试过了,还是不行
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");
}
}
不是,获取到的值是原来的值,不是TextBox中修改之后的值
<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();
}
我是这样弄的,你看下代码,应该怎么改啊?<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>