簡體   English   中英

動態將鏈接按鈕添加到ASP網格視圖

[英]Dynamically Add Link Button To ASP Grid View

我試圖在C#語法中使用以下代碼將鏈接按鈕添加到asp:gridview。 輸出窗口顯示添加的文本標簽,因此似乎代碼可以按需進行迭代。 但是,在頁面加載時,沒有鏈接按鈕。

我應該如何設置以便加載鏈接按鈕?

    protected void gvRR_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
    string[] rrar= new string[] { "Value Basis For Customer Support:" };
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        foreach (TableCell row in e.Row.Cells)
        {
            if (rrar.Any(x => x == e.Row.Cells[1].Text))
            {
                LinkButton lb = new LinkButton();
                lb.ID = "lbcoded";
                lb.Text = e.Row.Cells[1].Text;
                e.Row.Cells[1].Controls.Add(lb);
                System.Diagnostics.Debug.Print("Label Added");
            }
        }
    }
}

您將嘗試盡早在ItemTemplate中添加LinkBut​​ton,而不是動態添加,這將使您的生活更輕松。 在RowDataBound中找到LinkBut​​ton並根據條件顯示/顯示。

或者,您可以嘗試在gvRR_RowCreated事件中添加LinkBut​​ton嗎?

protected void gvRR_RowCreated(object sender, GridViewRowEventArgs e)
{
   //Put your code of add link buttone
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM