I figured out what the problem was. It turns out that the viewstate
information for the DataGrid is loaded in sometime between the Page_Init
and Page_Load, so if I wanted to recreate the columns on postback I had
to add the code to do it inside Page_Init instead of Page_Load..
Everything works fine now!
Allen K <x******@hotmail.com> wrote in
news:Xns94C4B443A49CEblahblahcom@198.161.157.145:
[quoted text, click to view] > OK that makes sense... But using the code below, I still can't seem to
> make the column appear even though I re-add it every time the page
> posts back?. If I rebind the datagrid each time then it seems to work
> fine, but I should be able to do it without rebinding shouldn't I?
>
> Allen
>
> "Bruno Sirianni" <brunosirianni@virgilio.it> wrote in
> news:4S_cc.27284$hc5.1251858@news3.tin.it:
>
>> DataGrid Columns are not in ViewState!
>>
>> If you add a column in codebehind you must readd this columns at all
>> postback.
>> The columns you created in the VS.NET DataGrid editor appear just
>> fine because are addedall the time when page is instanced!
>>
>> Your code is ok!
>>
>> Brun
>>
>> "Allen K" <x******@hotmail.com> wrote in message
>> news:Xns94C490DF661C3blahblahcom@198.161.157.145...
>>> Hi,
>>>
>>> I'm programmatically creating a HyperLink column for my datagrd ( in
>>> addition to Bound Columns created through the VS.NET Visual
>>> Interface ). However, when a Postback occurs, this column simply
>>> disappears, as if it doesn't exist in ViewState.. However, the
>>> columns I created in the VS.NET DataGrid editor appear just fine..
>>> Can someone help me??
>>>
>>> Heres my code:
>>>
>>> private void Page_Load( object sender, System.EventArgs e )
>>> {
>>> HyperLinkColumn viewDetails = new HyperLinkColumn();
>>>
>>> viewDetails.DataNavigateUrlField = UConst.COL_USERID;
>>> viewDetails.DataNavigateUrlFormatString =
>>> Constants.URL_VIEWUSER + "?userID={0}";
>>>
>>> viewDetails.Text = "View Details";
>>> viewDetails.HeaderText = "Details";
>>>
>>> TemplateColumn vd = new TemplateColumn();
>>>
>>> dgSearchResults.Columns.Add( viewDetails );
>>>
>>> if( !IsPostBack )
>>> {
>>> Initialize();
>>> //SetupDataGridColumns();
>>>
>>>
>>> }
>>>
>>> }
>>>
>>> I've also tried adding this to the If( !IsPostBack ) block and that
>>> doesn't seem to work either..
>>>
>>> Any help would be much appreciated! Thanks!
>>> Allen
>>
>>
>