无法使用datatable从gridview的数据绑定字段中获取值 [英] Unable to fetch value from databound field of gridview using datatable
问题描述
我正在使用数据表来绑定购物车的gridview。
我已经在gridview中获取了编辑,更新和取消的命令字段。
在GridView_RowUpdating事件中,我无法获得Quantity的值。
我的DataTable包含
列名 - 数据类型
ProductId - int
ProductImg - varchar
ProductName - varchar
数量 - int
价格 - 小数
总计 - 十进制
在.aspx文件中,
Gridview:
我已将所有列作为boundfields。
和所有列除了Quantity为readonly。
我已将编辑,更新,删除作为命令字段
和编辑/更新字段转换为模板字段。
我的.aspx.cs文件
I am using a datatable to bind gridview for shopping cart.
I have taken command field for Edit, Update and Cancel in gridview.
On its GridView_RowUpdating Event, I am not able to get the value of Quantity.
My DataTable Contains
Column Name - datatype
ProductId - int
ProductImg - varchar
ProductName - varchar
Quantity - int
Price - decimal
Total - decimal
In .aspx file,
Gridview:
I have taken all the columns as boundfields.
and all columns except Quantity as readonly.
I have taken Edit,Update, Delete as Command Field
and Edit/Update Field is converted into template field.
My .aspx.cs file
protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
DataTable cart = (DataTable)Session["Scart"];
GridViewRow row = GridView2.Rows[e.RowIndex];
string abc =
cart.Rows[row.DataItemIndex]["ProductQuantity"] = ((TextBox(row.Cells[3].Controls[0])).Text;
cart.AcceptChanges();
GridView2.EditIndex = -1;
Session["Scart"] = cart;
GridView2.DataSource = Session["Scart"];
GridView2.DataBind();
}
在行以粗体突出显示,我在更新gridview行时没有得到数量值。
我在更新时得到旧的数量值。没有得到更新的值。
请帮帮我......
可能是什么原因?
In the line highlighted in bold, I am not getting the Quantity value while Updating the gridview row.
I am getting the old value of quantity while updating. Not getting the updated value.
Please help me. . .
What can be the reason ??
推荐答案
我猜原因是PostBack
问题。
检查后绑定
GridView
! IsPostBack
I guess the reason isPostBack
issue.
Bind theGridView
after checking!IsPostBack
private void Page_Load()
{
if (!IsPostBack)
{
// Bind your GridView here.
BindGridView();
}
}
你能用aspx和aspx.cs文件提供你的整个代码吗?
can you please provide your whole code with aspx and aspx.cs file ?
>
这篇关于无法使用datatable从gridview的数据绑定字段中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!