Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Gridview binding twice

Reply
Thread Tools

Gridview binding twice

 
 
Julia B
Guest
Posts: n/a
 
      07-03-2009

All

This relates to .Net 2.0 using Visual Studio 2005.

I've got a gridview in a content page bound to an objectdatasource. The
datasource's SelectMethod calls on a function in a sub.

I do not call the gridview databind method on page load. However I do call
it after the user has filled out some fields (not in the gridview) and
pressed a submit button (which saves some data to tables which the gridview
will display the results of). This all works fine, then after the code on the
submit button is completed, I get an error because the gridview databind
method runs again without me calling it. Why? Can anyone tell me why the
databind method runs a second time when I'm not calling it? How do I stop it?

The datagrid/datasource code is as follows:

<asp:GridView ID="UploadResultsGrid" runat="server" AllowPaging="True"
AllowSorting="True" BorderColor="#D9D5D2" BorderStyle="Solid"
BorderWidth="1pt"
DataSourceID="UploadResultsDataSource" Font-Names="Tahoma"
TabIndex="8">
<RowStyle VerticalAlign="Top" />
<HeaderStyle BackColor="#D9D5D2" ForeColor="#D7451A"
HorizontalAlign="Left" VerticalAlign="Top" />
</asp:GridView>

<asp:ObjectDataSource ID="UploadResultsDataSource" runat="server"
SelectMethod="FillDataGridParam"
TypeName="RC_Web_FirestormAUCalibration.CommonUtil ities">
<SelectParameters>
<asparameter DefaultValue="GetCalibrationRecords"
Name="spName" />
<asparameter DefaultValue="@serialnumberid" Name="ParamName" />
<asparameter DefaultValue="Integer" Name="ParamType" />
<asparameter DefaultValue="0" Name="Paramlength" />
<asp:ControlParameter ControlID="SerialNumberTB"
DefaultValue="Null" Name="ParamValue"
PropertyName="Text" />
</SelectParameters>
</asp:ObjectDataSource>

Thanks in advance.
Julia


 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      07-04-2009
On 3 Jul., 15:27, Julia B <(E-Mail Removed)> wrote:
> All
>
> This relates to .Net 2.0 using Visual Studio 2005.
>
> I've got a gridview in a content page bound to an objectdatasource. The
> datasource's SelectMethod calls on a function in a sub.
>
> I do not call the gridview databind method on page load. However I do call
> it after the user has filled out some fields (not in the gridview) and
> pressed a submit button (which saves some data to tables which the gridview
> will display the results of). This all works fine, then after the code on the
> submit button is completed, I get an error because the gridview databind
> method runs again without me calling it. Why? Can anyone tell me why the
> databind method runs a second time when I'm not calling it? How do I stop it?
>
> The datagrid/datasource code is as follows:
>
> <asp:GridView ID="UploadResultsGrid" runat="server" AllowPaging="True"
> AllowSorting="True" BorderColor="#D9D5D2" BorderStyle="Solid"
> BorderWidth="1pt"
> * * * * DataSourceID="UploadResultsDataSource" Font-Names="Tahoma"
> TabIndex="8">
> * * * * <RowStyle VerticalAlign="Top" />
> * * * * <HeaderStyle BackColor="#D9D5D2" ForeColor="#D7451A"
> HorizontalAlign="Left" VerticalAlign="Top" />
> * * </asp:GridView>
>
> * * <asp:ObjectDataSource ID="UploadResultsDataSource" runat="server"
> SelectMethod="FillDataGridParam"
> * * * * TypeName="RC_Web_FirestormAUCalibration.CommonUtil ities">
> * * * * <SelectParameters>
> * * * * * * <asparameter DefaultValue="GetCalibrationRecords"
> Name="spName" />
> * * * * * * <asparameter DefaultValue="@serialnumberid" Name="ParamName" />
> * * * * * * <asparameter DefaultValue="Integer" Name="ParamType" />
> * * * * * * <asparameter DefaultValue="0" Name="Paramlength" />
> * * * * * * <asp:ControlParameter ControlID="SerialNumberTB"
> DefaultValue="Null" Name="ParamValue"
> * * * * * * * * PropertyName="Text" />
> * * * * </SelectParameters>
> * * </asp:ObjectDataSource>
>
> Thanks in advance.
> Julia


What error do you get? I think you bind your grid on postback again
(when submit button is pressed)
 
Reply With Quote
 
 
 
 
Julia B
Guest
Posts: n/a
 
      07-06-2009
Hi Alexey

The error I get is that the query string is the wrong input type. The query
string involves some text in a text box, which would be empty on post back so
that would make sense.

How do I stop the grid from rebinding on postback? Is that possible?

Julia

"Alexey Smirnov" wrote:

> On 3 Jul., 15:27, Julia B <(E-Mail Removed)> wrote:
> > All
> >
> > This relates to .Net 2.0 using Visual Studio 2005.
> >
> > I've got a gridview in a content page bound to an objectdatasource. The
> > datasource's SelectMethod calls on a function in a sub.
> >
> > I do not call the gridview databind method on page load. However I do call
> > it after the user has filled out some fields (not in the gridview) and
> > pressed a submit button (which saves some data to tables which the gridview
> > will display the results of). This all works fine, then after the code on the
> > submit button is completed, I get an error because the gridview databind
> > method runs again without me calling it. Why? Can anyone tell me why the
> > databind method runs a second time when I'm not calling it? How do I stop it?
> >
> > The datagrid/datasource code is as follows:
> >
> > <asp:GridView ID="UploadResultsGrid" runat="server" AllowPaging="True"
> > AllowSorting="True" BorderColor="#D9D5D2" BorderStyle="Solid"
> > BorderWidth="1pt"
> > DataSourceID="UploadResultsDataSource" Font-Names="Tahoma"
> > TabIndex="8">
> > <RowStyle VerticalAlign="Top" />
> > <HeaderStyle BackColor="#D9D5D2" ForeColor="#D7451A"
> > HorizontalAlign="Left" VerticalAlign="Top" />
> > </asp:GridView>
> >
> > <asp:ObjectDataSource ID="UploadResultsDataSource" runat="server"
> > SelectMethod="FillDataGridParam"
> > TypeName="RC_Web_FirestormAUCalibration.CommonUtil ities">
> > <SelectParameters>
> > <asparameter DefaultValue="GetCalibrationRecords"
> > Name="spName" />
> > <asparameter DefaultValue="@serialnumberid" Name="ParamName" />
> > <asparameter DefaultValue="Integer" Name="ParamType" />
> > <asparameter DefaultValue="0" Name="Paramlength" />
> > <asp:ControlParameter ControlID="SerialNumberTB"
> > DefaultValue="Null" Name="ParamValue"
> > PropertyName="Text" />
> > </SelectParameters>
> > </asp:ObjectDataSource>
> >
> > Thanks in advance.
> > Julia

>
> What error do you get? I think you bind your grid on postback again
> (when submit button is pressed)
>

 
Reply With Quote
 
Julia B
Guest
Posts: n/a
 
      07-06-2009

Alexey, on further investigation, following your comment, I've worked out the
steps taken and they seem very bizarre:

1 - Page opens the first time by the user (gridview fill does not happen)
2 - User selects value from a drop down list (postback happens but gridview
fill still does not happen)
3 - User enters data into entry fields and presses the submit button - this
is what then happens in code:
(a) postback happens
(b) my code runs - ie. all the changes to the data in the back end SQL
database
(c) the gridview fill tries to happen and then the error occurs, I assume
because the postback happened earlier

Why on earth does the gridview fill not happen on the first postback but
does on the second? And how can I change this?

Thanks in advance.
Julia


"Alexey Smirnov" wrote:

> On 3 Jul., 15:27, Julia B <(E-Mail Removed)> wrote:
> > All
> >
> > This relates to .Net 2.0 using Visual Studio 2005.
> >
> > I've got a gridview in a content page bound to an objectdatasource. The
> > datasource's SelectMethod calls on a function in a sub.
> >
> > I do not call the gridview databind method on page load. However I do call
> > it after the user has filled out some fields (not in the gridview) and
> > pressed a submit button (which saves some data to tables which the gridview
> > will display the results of). This all works fine, then after the code on the
> > submit button is completed, I get an error because the gridview databind
> > method runs again without me calling it. Why? Can anyone tell me why the
> > databind method runs a second time when I'm not calling it? How do I stop it?
> >
> > The datagrid/datasource code is as follows:
> >
> > <asp:GridView ID="UploadResultsGrid" runat="server" AllowPaging="True"
> > AllowSorting="True" BorderColor="#D9D5D2" BorderStyle="Solid"
> > BorderWidth="1pt"
> > DataSourceID="UploadResultsDataSource" Font-Names="Tahoma"
> > TabIndex="8">
> > <RowStyle VerticalAlign="Top" />
> > <HeaderStyle BackColor="#D9D5D2" ForeColor="#D7451A"
> > HorizontalAlign="Left" VerticalAlign="Top" />
> > </asp:GridView>
> >
> > <asp:ObjectDataSource ID="UploadResultsDataSource" runat="server"
> > SelectMethod="FillDataGridParam"
> > TypeName="RC_Web_FirestormAUCalibration.CommonUtil ities">
> > <SelectParameters>
> > <asparameter DefaultValue="GetCalibrationRecords"
> > Name="spName" />
> > <asparameter DefaultValue="@serialnumberid" Name="ParamName" />
> > <asparameter DefaultValue="Integer" Name="ParamType" />
> > <asparameter DefaultValue="0" Name="Paramlength" />
> > <asp:ControlParameter ControlID="SerialNumberTB"
> > DefaultValue="Null" Name="ParamValue"
> > PropertyName="Text" />
> > </SelectParameters>
> > </asp:ObjectDataSource>
> >
> > Thanks in advance.
> > Julia

>
> What error do you get? I think you bind your grid on postback again
> (when submit button is pressed)
>

 
Reply With Quote
 
Julia B
Guest
Posts: n/a
 
      07-06-2009

Hi Alexey, sorry to deluge you with responses, but I've now fixed this. I've
changed the objectdatasource select parameter to a session variable rather
than getting the value from a field, then it doesn't matter if the page
postback clears the field - the session variable stays the same and the
gridview fill works.

I'm still confused as to why the fill would automatically happen on some
postbacks but not others and would appreciate knowing if it's possible to
control exactly when this happens, but otherwise I'm sorted.

Thanks for your help on this.

Julia

"Alexey Smirnov" wrote:

> On 3 Jul., 15:27, Julia B <(E-Mail Removed)> wrote:
> > All
> >
> > This relates to .Net 2.0 using Visual Studio 2005.
> >
> > I've got a gridview in a content page bound to an objectdatasource. The
> > datasource's SelectMethod calls on a function in a sub.
> >
> > I do not call the gridview databind method on page load. However I do call
> > it after the user has filled out some fields (not in the gridview) and
> > pressed a submit button (which saves some data to tables which the gridview
> > will display the results of). This all works fine, then after the code on the
> > submit button is completed, I get an error because the gridview databind
> > method runs again without me calling it. Why? Can anyone tell me why the
> > databind method runs a second time when I'm not calling it? How do I stop it?
> >
> > The datagrid/datasource code is as follows:
> >
> > <asp:GridView ID="UploadResultsGrid" runat="server" AllowPaging="True"
> > AllowSorting="True" BorderColor="#D9D5D2" BorderStyle="Solid"
> > BorderWidth="1pt"
> > DataSourceID="UploadResultsDataSource" Font-Names="Tahoma"
> > TabIndex="8">
> > <RowStyle VerticalAlign="Top" />
> > <HeaderStyle BackColor="#D9D5D2" ForeColor="#D7451A"
> > HorizontalAlign="Left" VerticalAlign="Top" />
> > </asp:GridView>
> >
> > <asp:ObjectDataSource ID="UploadResultsDataSource" runat="server"
> > SelectMethod="FillDataGridParam"
> > TypeName="RC_Web_FirestormAUCalibration.CommonUtil ities">
> > <SelectParameters>
> > <asparameter DefaultValue="GetCalibrationRecords"
> > Name="spName" />
> > <asparameter DefaultValue="@serialnumberid" Name="ParamName" />
> > <asparameter DefaultValue="Integer" Name="ParamType" />
> > <asparameter DefaultValue="0" Name="Paramlength" />
> > <asp:ControlParameter ControlID="SerialNumberTB"
> > DefaultValue="Null" Name="ParamValue"
> > PropertyName="Text" />
> > </SelectParameters>
> > </asp:ObjectDataSource>
> >
> > Thanks in advance.
> > Julia

>
> What error do you get? I think you bind your grid on postback again
> (when submit button is pressed)
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView binding - how to stop initial binding Amit ASP .Net 6 10-24-2006 08:06 AM
GridView Hierarchical View - Gridview in Gridview =?Utf-8?B?bWdvbnphbGVzMw==?= ASP .Net 1 05-09-2006 06:48 PM
twice(twice(x)) Kiuhnm C++ 2 04-01-2006 04:41 PM
Binding NULL column causing Page_Load to run twice T-Bone ASP .Net 0 07-06-2004 12:24 PM
Data Binding - using inline code vs. functions vs. straight binding Jordan ASP .Net 2 02-10-2004 08:32 PM



Advertisments