【发布时间】:2014-03-13 05:23:56
【问题描述】:
我有一个 GridView,它有一个列 Status,它在每一行中都有默认值 False(在标签中)。
有一列名为Student,这是链接按钮。所以当用户点击学生姓名时
打开一个gridview 以显示该用户的数据。我更改第二个 GridView 的数据,然后保存它。所以当这个数据成功保存时。我想将该特定行的第一个 GridView 的状态从 False 修改为 True。
所以请建议我怎么做?
是否需要再次绑定GridView。有没有什么简单的方法,请告诉我。
所以主要问题是如何根据一些操作修改 GridView 中的特定单元格值。
我正在编写我正在尝试的代码。 我正在保存父 GridView 行号。是 ViewState。
protected void btnSave_Click(object sender, EventArgs e)
{
if (ViewState["RowIndexPOS"] != null)
{
int iRowIndex = Convert.ToInt32(ViewState["RowIndexPOS"]);
Label lblStatus = (Label)GridViewMultiplePOSAssociationId.Rows[iRowIndex].FindControl("LabelStatusPendingPOSId");
//Means all rows in GridView are successfully associated
if (table.Rows.Count == iResultCount)
{
lblStatus.Text = "Associated";
}
else
{
lblStatus.Text = "Pending";
}
}
}
绑定第一个gridview的代码
DataTable dt = new DataTable();
DataRow dr = null;
dt.Columns.Add(new DataColumn("Row Number", typeof(string)));
dt.Columns.Add(new DataColumn("POS Id", typeof(string)));
dt.Columns.Add(new DataColumn("Action", typeof(string)));
dt.Columns.Add(new DataColumn("Status", typeof(string)));
for (int index = 0; index < m_listStrPendingListOfPOS.Count; index++)
{
dr = dt.NewRow();
int iRowNo = index + 1;
dr["Row Number"] = iRowNo;
string strGridViewPOSId = m_listStrPendingListOfPOS[index];
dr["POS Id"] = strGridViewPOSId;
dr["Action"] = string.Empty;
dr["Status"] = "Pending";
dt.Rows.Add(dr);
}
ViewState["POSTable"] = dt;
GridViewMultiplePOSAssociationId.DataSource = dt;
GridViewMultiplePOSAssociationId.DataBind();
当我尝试这个时。每一行的状态列都是空的。将此设置为关联后。
【问题讨论】:
-
如果父gridview可以通过第二个gridview的save功能访问,那么通过学生id或者父行号信息,你就可以改变status的值。跨度>
-
无法访问父 GridView。但我有行号。信息。
-
有很多方法可以做到这一点。如果父级绑定到数据源并且可以在 save func 中访问,则可以影响更改。或者,如果父级绑定到数据库,您可以更改并重新加载。没有给出完整的场景很难评论。
-
父绑定到数据集。
-
上述函数有错误吗?在实际更改它的值之前检查 lblStatus 是否不为空会很好。