problem with gridview

  • Thread starter Thread starter Diana Fijman
  • Start date Start date
D

Diana Fijman

Hello everyone.

I have the following problem:

I'm building a website, that as a fact that is entered into a
textbox, loading the contents of the query to a datatable, I put as
datasource of a gridview, and then do the databind, the data are listed
without inconvenience. The gridview has a template column defined as
field with the following code:

<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server"
ImageUrl="~/link.jpg" CommandName="Select" />
</ItemTemplate>
</asp:TemplateField>

Clicking on any row of the gridview, by event
OnSelectedIndexChanged, I access the data in that row and do a
response.redirect to a second page to enter the data I need,
based on the parameters I pass url, then do the update to the table,
All this works fine and the data is updated. In the second
page return a session variable so that when you reload the
first page asks for this variable and if true return
to make the original query to the table to update the gridview, the
Indeed I did the debug and in theory this works, but the change is not
reflected in the gridview. What is striking is that for example, if I move
page of gridview, to return to the first (where the row modified)
if change is reflected.
This is the code I use in the Page_Load of the first page:if
(Session["Refresh"] != null)
{
if (Session["Refresh"].ToString() == "True")
{

Session.Remove("Refresh");

gv(); ---- function that makes the query to fill the
datatable and then databind
}
}

Would greatly appreciate some guidance on what may be happening.

Greetings,
 
Would greatly appreciate some guidance on what may be happening.

My guess would be the GridView is being "reconstituted" by ViewState.

But, let's break down the problem a bit, as I am not sure the session
variable is your best method of conquering this problem.

One important question: How are you initially filling the GridView
'state"? Is this something automatically done when the user hits the
page. If so, the "cancel" operation should merely recall the page and
allow the page to do the fill again as a fresh page view.

If there are additional bits of information, you need a way of keeping
control of them, of course. Depending on what you are doing, you might
need some form of caching of the initial state.

I guess I need more information to give you a better answer, but
hopefully this stirs some ideas.

Peace and Grace,


--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Gregory, thank you very much for your reply.

I'm rather new in ASP.NET, so, I'm not sure about what you mean when you
talk about the gridview state.

This is the source of my gridview control:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

AllowPaging="True" CellPadding="4" HorizontalAlign="Center"

OnPageIndexChanging="GridView1_PageIndexChanging"

BorderColor="#3366CC"

BorderStyle="None" BorderWidth="1px"

OnSelectedIndexChanged="IngresarStock" >


<RowStyle BackColor="White" BorderColor="#3366CC" ForeColor="#003399"

HorizontalAlign="Left" VerticalAlign="Middle"/>

<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />

<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left"
/>

<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />


<Columns >

<asp:BoundField DataField="codigo" ReadOnly="true" HeaderText="Codigo"/>

<asp:BoundField DataField="articulo" ReadOnly="true"
HeaderText="Medicamento" />

<asp:BoundField DataField="stockdonado" ReadOnly="true" HeaderText="Stock
Donado" />

<asp:BoundField DataField="stockcomprado" ReadOnly="true" HeaderText="Stock
Comprado" />

<asp:TemplateField>

<ItemTemplate>

<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/link.jpg"
CommandName="Select" />

</ItemTemplate>

</asp:TemplateField>

</Columns>

</asp:GridView>



and the event raised onselectionindexchanged:



protected void IngresarStock(object sender, EventArgs e)
{
int indice = GridView1.SelectedIndex + (GridView1.PageSize *
GridView1.PageIndex);
String codi = GridView1.Rows[indice].Cells[0].Text.ToString();
String nombre = GridView1.Rows[indice].Cells[1].Text.ToString();
String donadoAnt =
GridView1.Rows[indice].Cells[2].Text.ToString();
String compradoAnt =
GridView1.Rows[indice].Cells[3].Text.ToString();

Response.Redirect("PopUpIngreso.aspx?Nombre=" + nombre +
"&Codigo=" + codi + "&Donado=" + donadoAnt + "&Comprado=" + compradoAnt);

Hope this helps

Thank you again

Diana G.Fijman
 
I'm rather new in ASP.NET, so, I'm not sure about what you mean when you
talk about the gridview state.

In the tag put:

EnableViewState="false"

Then rerun the page and see if it either a) fixes it or b) exposes a worse
problem (error message, etc).

Peace and Grace,

--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
I've tried putting EnableViewState="false" in the tag. It doesn't expone any
error such as an error message, but the second page is not loading, the
result is that when I clikc at any row of the gridview, it dissapears, and
nothing else I can do at this point.

Thank you again for your reply.
 
I've tried putting EnableViewState="false" in the tag. It doesn't
expone any error such as an error message, but the second page is not
loading, the result is that when I clikc at any row of the gridview,
it dissapears, and nothing else I can do at this point.

Thank you again for your reply.

That means you were not populating it at all and it was pulling all of its
information from viewstate. The good thing is you now know what is
happening.

I just went back and looked at your solution again. You have multiple pages
involved in the transaction. You don't need to do this.

Check out this blog entry and see if it helps you think through the problem
in a different manner:
http://bit.ly/8gVcwI

The use of separate pages for a single operation often burns you in
ASP.NET.

As for fixing the problem, you are missing the transfer of some necesary
data or not calling a routine that sets up the grid. But look at the blog
entry and it might help you refactor the code so it works more efficiently.

Peace and Grace,


--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Thank you very much Gregory. I'll try to change my code using panels, and
tell you then what happen's.

Diana
 
Hello again. I've changed my code using panels, but the problem persists,
so, I think something is not working properly with the databinding, but I
don't really know how to continue.

Thank you again.
 
Hello again. I've changed my code using panels, but the problem
persists, so, I think something is not working properly with the
databinding, but I don't really know how to continue.

Describe what you are doing, step by step. Like:

1. User clicks on x.aspx
2. User selects item from drop down
3. Page refreshes and user sees textbox
4. User fills in textbox and clicks button

Whatever the flow is. Describe it from how it should work. That will
give you a decent use case from which to work. It will also give anyone
trying to help a decent map to help you with.

As this one is pretty buried now, you might want to start a new thread
with "Here is what I am trying to do" followed by how you are trying to
solve it followed by the problems you are having.

Peace and Grace,

--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Back
Top