Gridview binding twice

Discussion in 'ASP .Net' started by Julia B, Jul 3, 2009.

  1. Julia B

    Julia B Guest

    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.CommonUtilities">
    <SelectParameters>
    <asp:parameter DefaultValue="GetCalibrationRecords"
    Name="spName" />
    <asp:parameter DefaultValue="@serialnumberid" Name="ParamName" />
    <asp:parameter DefaultValue="Integer" Name="ParamType" />
    <asp:parameter DefaultValue="0" Name="Paramlength" />
    <asp:ControlParameter ControlID="SerialNumberTB"
    DefaultValue="Null" Name="ParamValue"
    PropertyName="Text" />
    </SelectParameters>
    </asp:ObjectDataSource>

    Thanks in advance.
    Julia
    Julia B, Jul 3, 2009
    #1
    1. Advertising

  2. On 3 Jul., 15:27, Julia B <> 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.CommonUtilities">
    >         <SelectParameters>
    >             <asp:parameter DefaultValue="GetCalibrationRecords"
    > Name="spName" />
    >             <asp:parameter DefaultValue="@serialnumberid" Name="ParamName" />
    >             <asp:parameter DefaultValue="Integer" Name="ParamType" />
    >             <asp:parameter 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)
    Alexey Smirnov, Jul 4, 2009
    #2
    1. Advertising

  3. Julia B

    Julia B Guest

    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 <> 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.CommonUtilities">
    > > <SelectParameters>
    > > <asp:parameter DefaultValue="GetCalibrationRecords"
    > > Name="spName" />
    > > <asp:parameter DefaultValue="@serialnumberid" Name="ParamName" />
    > > <asp:parameter DefaultValue="Integer" Name="ParamType" />
    > > <asp:parameter 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)
    >
    Julia B, Jul 6, 2009
    #3
  4. Julia B

    Julia B Guest

    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 <> 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.CommonUtilities">
    > > <SelectParameters>
    > > <asp:parameter DefaultValue="GetCalibrationRecords"
    > > Name="spName" />
    > > <asp:parameter DefaultValue="@serialnumberid" Name="ParamName" />
    > > <asp:parameter DefaultValue="Integer" Name="ParamType" />
    > > <asp:parameter 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)
    >
    Julia B, Jul 6, 2009
    #4
  5. Julia B

    Julia B Guest

    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 <> 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.CommonUtilities">
    > > <SelectParameters>
    > > <asp:parameter DefaultValue="GetCalibrationRecords"
    > > Name="spName" />
    > > <asp:parameter DefaultValue="@serialnumberid" Name="ParamName" />
    > > <asp:parameter DefaultValue="Integer" Name="ParamType" />
    > > <asp:parameter 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)
    >
    Julia B, Jul 6, 2009
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jordan
    Replies:
    2
    Views:
    2,513
    Jordan
    Feb 10, 2004
  2. T-Bone
    Replies:
    0
    Views:
    512
    T-Bone
    Jul 6, 2004
  3. Amit
    Replies:
    6
    Views:
    13,739
    Assimalyst
    Oct 24, 2006
  4. Replies:
    2
    Views:
    838
    Kevin Grover
    Oct 20, 2006
  5. Kiuhnm

    twice(twice(x))

    Kiuhnm, Apr 1, 2006, in forum: C++
    Replies:
    2
    Views:
    381
    Kiuhnm
    Apr 1, 2006
Loading...

Share This Page