DataGrid does not recognize Select, Edit, etc buttons when EnableViewState = False

G

Guest

Hello
i saw some performance recommendations and one of them i
"Set datagrid's enableviewstate to false
But i have a CRUD page and it not fires datagrid events like ItemCommand, SelectedIndexChanged, EditCommand

Here is the definition of my datagrid. How can i do to work without viewstate

<asp:datagrid id="dgEdicion" runat="server" AutoGenerateColumns="False" EnableViewState="False" ><SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#CC3333"></SelectedItemStyle><HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#333333"></HeaderStyle><Columns><asp:ButtonColumn Text="Seleccionar" CommandName="Select"></asp:ButtonColumn><asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Grabar" CancelText="Cancelar" EditText="Editar"></asp:EditCommandColumn><asp:BoundColumn DataField="CustomerID" SortExpression="CustomerID" HeaderText="CustomerID"></asp:BoundColumn><asp:BoundColumn DataField="CompanyName" SortExpression="CompanyName" HeaderText="Company Name"></asp:BoundColumn><asp:BoundColumn DataField="ContactName" SortExpression="ContactName" HeaderText="Contact Name"></asp:BoundColumn></Columns><PagerStyle HorizontalAlign="Right" ForeColor="Black" BackColor="White"></PagerStyle></asp:DataGrid

Thank you
 
M

Marina

Are you reloading the data into the grid every time?

Jose Flores said:
Hello,
i saw some performance recommendations and one of them is
"Set datagrid's enableviewstate to false"
But i have a CRUD page and it not fires datagrid events like ItemCommand,
SelectedIndexChanged, EditCommand.
Here is the definition of my datagrid. How can i do to work without viewstate?

<asp:datagrid id="dgEdicion" runat="server" AutoGenerateColumns="False"
EnableViewState="False" ><SelectedItemStyle Font-Bold="True"
ForeColor="White" BackColor="#CC3333"></SelectedItemStyle><HeaderStyle
Font-Bold="True" ForeColor="White"
BackColor="#333333"></HeaderStyle><Columns><asp:ButtonColumn
Text="Seleccionar"
CommandName="Select"></asp:ButtonColumn><asp:EditCommandColumn
ButtonType="LinkButton" UpdateText="Grabar" CancelText="Cancelar"
EditText="Editar"></asp:EditCommandColumn><asp:BoundColumn
DataField="CustomerID" SortExpression="CustomerID"
HeaderText="CustomerID"></asp:BoundColumn><asp:BoundColumn
DataField="CompanyName" SortExpression="CompanyName" HeaderText="Company
Name"></asp:BoundColumn><asp:BoundColumn DataField="ContactName"
SortExpression="ContactName" HeaderText="Contact
 
P

Paul

Jose, I've had this happen to me and I've seen a lot of posts
complaining about similar issues. I don't remember ever seeing an
"official" sounding answer to it but all of a sudden certain framework
generated event handlers have been known to quit. They never fire after
something whacks them (but what whacks them?)

I work in VB and I've solved the problem by deleting the handlers, and
then reselecting them from the dropdownlists at the top of the code
behind. In VB this is relatively simple, and more a pain in the butt
than anything else. Of course, then I paste my code back into the
handlers. It has always worked to clear up the problem. The problem
has recurred on me about 3 times in the last eight months. Each time I
find it a little easier to recognize the issue, but the first time was a
bitch. HUH??? WHA???
The event won't FIRE??

The only thing I can think of that could be seen as a "screwup" that
would lead to this is something that doesn't make sense: I would be
fiddling in the HTML of ASP.NET and screw it up and there would be
problems rendering the controls, etc. This happens all the time, of
course, and should have no bearing on the code behind. That's what my
logical mind says, but I'm not that experienced to know for sure. All I
know is that it's the only thing I can think of that would be something
I screwed up at such times.

IF you work in C# you may have to type the handlers back in manually
because I don't think it works the same as VB.

~Paul
 
G

Guest

Yes, i reload the data every time.
When user clicks Edit button i change EdiItemIndex property
"dgEdicion.EditItemIndex = e.Item.ItemIndex" after setting this property i need to reload the data
 
G

Guest

Hello Pau
Thank you for your answe
sorry i dont speak english well, i speak spanish, but i've tried to understando your answer (50%
First thing to say is that my question is not high priority, i can put EnableViewState=True and there is no problem,
but i wan't to understand why events doesn't fire when EnableViewState=Fals
0. im working with V
1. i've deleted the handlers and reselected again and pasted the code but the events don't fir
2. the other thing i did is put AutoEventWireup="True" in Page directive and wrote this procedure
Public Sub dgEdicion_EditCommand(ByVal sender As System.Object, ByVal e As System.EventArgs
Response.Write("Editar"
End Su
and events don't fir
3. i've added attributes to <asp:datagrid ==> OnUpdateCommand="Actualizar" OnCancelCommand="Cancelar" OnEditCommand="Editar"
and again events don't fir

So my conclussion is datagrids events don't fire when enableviewstate=false?. am i right?
Thank you again.
 
G

Guest

My understanding is that if viewstate is off, a datagrid won't get its events, because that's the only way it can compare new vs. old to see what happened. For example, my pager works fine on the grid, but if I turn off viewstate and do nothing else, the grid doesn't get PageIndexChanged. Hopefully a higher power will weigh in on this with the definitive answer

----- Jose Flores wrote: ----

Hello
i saw some performance recommendations and one of them i
"Set datagrid's enableviewstate to false
But i have a CRUD page and it not fires datagrid events like ItemCommand, SelectedIndexChanged, EditCommand

Here is the definition of my datagrid. How can i do to work without viewstate

<asp:datagrid id="dgEdicion" runat="server" AutoGenerateColumns="False" EnableViewState="False" ><SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#CC3333"></SelectedItemStyle><HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#333333"></HeaderStyle><Columns><asp:ButtonColumn Text="Seleccionar" CommandName="Select"></asp:ButtonColumn><asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Grabar" CancelText="Cancelar" EditText="Editar"></asp:EditCommandColumn><asp:BoundColumn DataField="CustomerID" SortExpression="CustomerID" HeaderText="CustomerID"></asp:BoundColumn><asp:BoundColumn DataField="CompanyName" SortExpression="CompanyName" HeaderText="Company Name"></asp:BoundColumn><asp:BoundColumn DataField="ContactName" SortExpression="ContactName" HeaderText="Contact Name"></asp:BoundColumn></Columns><PagerStyle HorizontalAlign="Right" ForeColor="Black" BackColor="White"></PagerStyle></asp:DataGrid

Thank you
 
N

Noel H

There was a talk by Marcie Robillard (aka DataGrid Girl) that I attended a
way back (TechEd03 - NZ). In it she talked about ViewState and DataGrid
events,

Here's the link the slides and code samples.
[blurb]
June 17, 2003: Western Michigan .NET Users Group
ASP.NET Datagrid Advanced Tips
Moves from a quick review into tips for working with (and without)
ViewState, checkboxes and radio buttons inside a Datagrid, and dynamically
creating Datagrid columns.
[slides: http://datagridgirl.com/talks/GRSlides.ppt
code samples: http://datagridgirl.com/talks/GRDemos.zip]
[/blurb]

Regards,
Noel H

Jose Flores said:
Hello,
i saw some performance recommendations and one of them is
"Set datagrid's enableviewstate to false"
But i have a CRUD page and it not fires datagrid events like ItemCommand,
SelectedIndexChanged, EditCommand.
Here is the definition of my datagrid. How can i do to work without viewstate?

<asp:datagrid id="dgEdicion" runat="server" AutoGenerateColumns="False"
EnableViewState="False" ><SelectedItemStyle Font-Bold="True"
ForeColor="White" BackColor="#CC3333"></SelectedItemStyle><HeaderStyle
Font-Bold="True" ForeColor="White"
BackColor="#333333"></HeaderStyle><Columns><asp:ButtonColumn
Text="Seleccionar"
CommandName="Select"></asp:ButtonColumn><asp:EditCommandColumn
ButtonType="LinkButton" UpdateText="Grabar" CancelText="Cancelar"
EditText="Editar"></asp:EditCommandColumn><asp:BoundColumn
DataField="CustomerID" SortExpression="CustomerID"
HeaderText="CustomerID"></asp:BoundColumn><asp:BoundColumn
DataField="CompanyName" SortExpression="CompanyName" HeaderText="Company
Name"></asp:BoundColumn><asp:BoundColumn DataField="ContactName"
SortExpression="ContactName" HeaderText="Contact
 

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

Top