Datagrid ViewState

  • Thread starter Alejandro Penate-Diaz
  • Start date
A

Alejandro Penate-Diaz

Hi. I am trying to reduce a DataGrid viewstate info by doing what this article says: http://authors.aspalliance.com/JimRoss/Articles/DatagridDietPartTwo.aspx .. I need to disable viewstate for all columns exept my button columns. Problem is that I can not access the Label controls within datagrid cells. I tried:

TableCell Cell3 = e.Item.Cells[3];

((Label)Cell3.Controls[1]).Text;




but then I get empty strings. Also inside a cell I found a LiteralControl and a Label in position 0 and 1 respectively but both are empty.
Here is a fragment of my datagrid and I need to retrieve programmaticaly the value for th Label in red.



<asp:datagrid id="DataGrid1" runat="server" Width="1000px" BackColor="AliceBlue" AllowSorting="True"
AutoGenerateColumns="False" Font-Size="Smaller">
<AlternatingItemStyle BackColor="GhostWhite"></AlternatingItemStyle>
<HeaderStyle Font-Size="Smaller" Font-Names="Arial" Font-Bold="True" Wrap="False" HorizontalAlign="Center"
BorderStyle="Groove" VerticalAlign="Middle" BackColor="GhostWhite"></HeaderStyle>
<Columns>
<asp:EditCommandColumn Visible="False" ButtonType="PushButton" UpdateText="Update" CancelText="Cancel"
EditText="Edit"></asp:EditCommandColumn>
<asp:ButtonColumn Text="View" ButtonType="PushButton" CommandName="Delete">
<HeaderStyle Width="50px"></HeaderStyle>
</asp:ButtonColumn>
<asp:TemplateColumn>
<HeaderStyle Width="200px"></HeaderStyle>
<ItemTemplate>
<asp:Label runat="server"
EnableViewState="False"
Text='<%# DataBinder.Eval(Container, "DataItem.Serial") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Serial") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>


Thanks,
Alejandro
 
K

Karl Seguin

Alejandro,
Keep in mind that blank/new lines are converted into server controls...this
is very likely what you are seeing with the LiteralControl. It makes it
_very_ difficult to refer to to controls by their position. You should try
givin your label an id and then doing:

Label myLabel = (Label)e.Item.FindControl("myLabelId") or something
similar...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
Hi. I am trying to reduce a DataGrid viewstate info by doing what this
article says:
http://authors.aspalliance.com/JimRoss/Articles/DatagridDietPartTwo.aspx . I
need to disable viewstate for all columns exept my button columns. Problem
is that I can not access the Label controls within datagrid cells. I tried:

TableCell Cell3 = e.Item.Cells[3];
((Label)Cell3.Controls[1]).Text;


but then I get empty strings. Also inside a cell I found a LiteralControl
and a Label in position 0 and 1 respectively but both are empty.
Here is a fragment of my datagrid and I need to retrieve programmaticaly the
value for th Label in red.



<asp:datagrid id="DataGrid1" runat="server" Width="1000px"
BackColor="AliceBlue" AllowSorting="True"
AutoGenerateColumns="False" Font-Size="Smaller">
<AlternatingItemStyle BackColor="GhostWhite"></AlternatingItemStyle>
<HeaderStyle Font-Size="Smaller" Font-Names="Arial" Font-Bold="True"
Wrap="False" HorizontalAlign="Center"
BorderStyle="Groove" VerticalAlign="Middle"
BackColor="GhostWhite"></HeaderStyle>
<Columns>
<asp:EditCommandColumn Visible="False" ButtonType="PushButton"
UpdateText="Update" CancelText="Cancel"
EditText="Edit"></asp:EditCommandColumn>
<asp:ButtonColumn Text="View" ButtonType="PushButton"
CommandName="Delete">
<HeaderStyle Width="50px"></HeaderStyle>
</asp:ButtonColumn>
<asp:TemplateColumn>
<HeaderStyle Width="200px"></HeaderStyle>
<ItemTemplate>
<asp:Label runat="server"
EnableViewState="False"
Text='<%# DataBinder.Eval(Container, "DataItem.Serial") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.Serial") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>


Thanks,
Alejandro
 
A

Alejandro Penate-Diaz

I did that and named my labels but I'am still getting empty strings and my
datagrid is fully populated, I just dont get it. any help?
alejandro.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top