2009-07-23 43 views
0

這似乎是不可能改變的GridView .Caption已設置一次之後。不能改變GridView的標題

一旦我設置標題,然後回傳內改變它,在代碼中似乎都正常,在頁面的PreRender,GridView控件的PreRender何

我不知道該怎麼做 - 網頁(和GridView也)PreRender事件在調試.Caption是正確的,但它與舊的標題渲染反正

頁似乎是設置一次標題渲染,雖然我改變了它。

我甚至試圖將其放置的UpdatePanel和更新,但它並沒有幫助。

任何人都可以建議的原因嗎? 在此先感謝。

回答

1

似乎是在這個例子在這裏工作,你可以發佈您的代碼?

<%@ Page Language="C#" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<script runat="server"> 

    protected void Page_Load(object sender, EventArgs e) 
    { 
     if (!IsPostBack) 
     { 
      System.Collections.Generic.List<int> Values = new System.Collections.Generic.List<int> { 1, 2, 3, 4, 5, 6, 7 }; 
      grdTest.DataSource = Values; 
      grdTest.DataBind(); 
     } 
    } 

    protected void btnSubmit_Click(object sender, EventArgs e) 
    { 
     grdTest.Caption = "test grid " + DateTime.Now.ToString(); 


    } 
</script> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
      <asp:GridView ID="grdTest" Caption="test grid" runat="server"> 
       <Columns> 
        <asp:TemplateField> 
         <ItemTemplate> 
          hello 
         </ItemTemplate> 
        </asp:TemplateField> 
       </Columns> 
      </asp:GridView> 

      <asp:Button ID="btnSubmit" runat="server" onclick="btnSubmit_Click" Text="Submit" /> 

    </div> 
    </form> 
</body> 
</html> 
+0

代碼相當長,但是這是有關部分 它的Page_Load 呼籲有沒有其他任務在整個代碼.Caption dgPublications.Caption =的String.Format(「訂單#{0}產品類型「,_currentOrderID); dgOrderContent.Caption = _currentPubID.HasValue?的String.Format( 「{0}內容」, Dictionaries.GetInstance(((MDSPage)this.Page).Database).PublicationIDs [_currentPubID.Value]): 的String.Format( 「訂單#{0}的內容」, _currentOrderID); dgOrderContent.DataBind(); – igor 2009-07-23 14:23:53