0
我有一個GridView
,當用戶點擊這個GridView
以外的按鈕時,要更新一個GridView
列,應該爲一個特定的行更新GridView
列。 因此,我在PostBack
中爲GridView
添加新數據。但是正如我們所知,PostBack
在按鈕事件之前被調用OnClick
。所以GridView
現在是綁定的。但我想根據OnClick
按鈕事件中的某些操作更新特定行的GridView
列值。 所以我試圖綁定GridView
在OnClick
按鈕事件也。但它沒有得到更新。 所以我主要懷疑是。如何在GridView之外的控件發生回發後更新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的代碼和按鈕點擊事件嗎? – Humpy
發佈一些代碼並告訴我們您是否可以使用UpdatePanels。答案取決於UpdatePanel是否是一個選項。 –
修改了這個問題。 – user3264676