【发布时间】:2014-03-13 14:52:15
【问题描述】:
我有一个GridView,当用户单击此GridView 之外的按钮时将更新它,应为特定行更新GridView 列。
所以我在PostBack 中为GridView 出价新数据。但正如我们所知,PostBack 在OnClick 按钮事件之前被调用。所以GridView此时是绑定的。但我希望根据OnClick 按钮事件中的一些操作更新特定行的GridView 列值。
所以我也尝试在OnClick 按钮事件中绑定GridView。但它没有得到更新。
所以我的主要疑问是。
这是否可以在导致PostBack 的点击事件中在PostBack 块中调用的方法中传递值?
private void bindTheGriView()
{
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;
//check for the flag. if the flag is true set status to Pending else to Associated
dr["Status"]=((Label)GridViewMultiplePOSAssociationId.Rows[index].FindControl("LabelStatusPendingPOSId")).Text;
dt.Rows.Add(dr);
}
ViewState["POSTable"] = dt;
GridViewMultiplePOSAssociationId.DataSource = dt;
GridViewMultiplePOSAssociationId.DataBind();
}
protected void btnSave_Click(object sender, EventArgs e)
{
bool statusFlag=false;
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";
}
}
//now call the binding method with the bool flag value
bindTheGriView();
}
不,我没有使用更新面板。
【问题讨论】:
-
你能展示一些gridview和按钮点击事件的代码吗?
-
发布一些代码并告诉我们您是否可以使用 UpdatePanels。答案将取决于 UpdatePanels 是否是一个选项。
-
修改了问题。
标签: c# asp.net gridview postback