0
嗨我有一個網格控件,我在哪裏綁定的貼紙列表。在上面的網格中,這是外側網格我有兩個按鈕創建貼紙和虛空貼紙。 貼紙基本上有三個屬性Active,Void和Expired顯示爲列中的文本。每次只能添加一個貼紙。另外,如果有活動的貼紙,則用戶不能添加另一張貼紙,除非其過期或無效。基於網格行啓用禁用按鈕
所以我想要的是,只要我的網格被加載,如果有一個文本活動的列創建/添加貼紙將被禁用和無效將啓用。我正在使用以下代碼
/// <summary>
/// Handles the RowDataBound event of the gvSticker control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewRowEventArgs"/> instance containing the event data.</param>
/// <remarks></remarks>
protected void gvSticker_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
if (Session["FisherId"] != null)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblStatus = (Label)e.Row.FindControl("lblStickerStatus");
if (lblStatus.Text.Contains("Active"))
{
btnAddSticker.Enabled = false;
btnVoidSticker.Enabled = true;
HyperLink hlStickerNum = (HyperLink)e.Row.FindControl("hlStickerNumber");
hlStickerNum.Attributes.Add("style",
"cursor:hand;text-decoration:underline;font-weight:bold;");
if (!string.IsNullOrEmpty(hlStickerNum.Text.Trim()))
{
string urlWithParameters = "Stickers.aspx?StickerId="
+ hlStickerNum.Text;
hlStickerNum.Attributes.Add("OnClick", "popWinNote('" +
urlWithParameters + "')");
}
}
else
{
btnAddSticker.Enabled = true;
btnVoidSticker.Enabled = false;
}
}
}
else
{
btnAddSticker.Enabled = true;
btnVoidSticker.Enabled = false;
}
}
它在網格的第一次加載時工作良好。但每當我改變網格的頁面索引時都會失敗。
更新
這裏有約束力,pageindexchanging事件
/// <summary>
/// Handles the PageIndexChanging event of the gvSticker control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewPageEventArgs"/> instance containing the event data.</param>
/// <remarks></remarks>
protected void gvSticker_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvSticker.PageIndex = e.NewPageIndex;
BindStickerGrid();
}
/// <summary>
/// Binds the sticker grid.
/// </summary>
/// <param name="stickers">collection of stickers.</param>
/// <remarks></remarks>
protected void BindStickerGrid()
{
if (Session["FisherId"] != null)
{
Collection<Sticker> _stickerCollection = _manager.GetStickerDetailsForGrid(Session["FisherId"].ToString(), "fisher");
if (_stickerCollection != null)
{
if (_stickerCollection.Count > 0)
{
gvSticker.DataSource = _stickerCollection;
gvSticker.DataBind();
}
}
}
}
看到我的問題,增加了PageIndex的改變和有約束力的方法 – 2011-01-05 11:42:01
我已經編輯我的答案更新。 – volpav 2011-01-05 12:36:56