Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is happening because the <code>OnRowDataBound</code> event of GridView is NOT called on next postback. This happens because by default viewstate of GridView is set true i.e. <code>EnableViewState</code> property of Gridview is <code>true</code>. When ViewState is on, Gridview stores data from the same and <code>OnRowDataBound</code> event is not called. Also, at this point View state will not be applied for your <code>linkButtons</code> as they aren't created in <code>page_load</code>.</p> <p>Try setting <code>EnableViewState</code> property to false for your gridview:</p> <pre><code>&lt;asp:GridView ID="CustomersGridView" OnRowDataBound="CustomersGridView_RowDataBound" EnableViewState="false" .... /&gt; </code></pre> <p>OR you can also bind your <code>GridView</code> in <code>page_Load</code> as:</p> <pre><code>protected void Page_Load(object sender, EventArgs e) { CustomersGrIdView.DataBind(); } </code></pre> <p>Now after every postback your <code>OnRowDataBound</code> event will be called and hence the <code>LinkButtons</code> will be available everytime.</p> <hr> <p><strong>NOTE:</strong> Setting <code>EnableViewState</code> property to false for gridview can be a bad practice to an extent, especially in scenarios of heavy data usages. Same goes for Binding gridview every time.</p> <p>When using dynamic controls, they exist only until the next postback.ASP.NET will not re-create a dynamically added control. If you need to re-create a control next time too on postback, you should perform the control creation in the <code>PageLoad</code> event handler.</p> <p>This will give you benefit of using view state with your dynamic control. Even though view state is normally restored before the <code>Page.Load</code> event, if you create a control in the handler for the <code>PageLoad</code> event, ASP.NET will apply any view state information that it has after the <code>PageLoad</code> event handler ends.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload