views:

361

answers:

1

It seems to be impossible to change GridView .Caption after it has been set once.

Once I set caption and then change it within postbacks, in the code all seem to be ok, on page PreRender, GridView PreRender and wherever

I have no idea what to do - on page (and GridView also) PreRender event while debugging the .Caption is proper, but it renders with old caption anyway

Page seems to be render with set-once caption although I changed it.

I even tried to place it to updatePanel and update it, but it didn't help.

Can anybody suggest the reason? thanks in advance.

A: 

Seems to be working here in this example, can you post your code?

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

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

<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"&gt;
<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>
Chris Mullins
The code is rather long but that's the relevant partIt calls from page_loadThere are no other assignments to .Caption in the whole code dgPublications.Caption = string.Format("Order# {0} product types", _currentOrderID); dgOrderContent.Caption = _currentPubID.HasValue ? string.Format("{0} content", Dictionaries.GetInstance(((MDSPage)this.Page).Database).PublicationIDs[_currentPubID.Value]) : string.Format("Order # {0} content", _currentOrderID); dgOrderContent.DataBind();
igor
Do you have the viewstate turned off? You may need to set it on every page load after the databind if you have it turned off.
Chris Mullins