|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Gridview binding twiceThis 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 On 3 Jul., 15:27, Julia B <Jul***@discussions.microsoft.com> wrote:
Show quoteHide quote > All What error do you get? I think you bind your grid on postback again> > 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 (when submit button is pressed) 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 Show quoteHide quote "Alexey Smirnov" wrote: > On 3 Jul., 15:27, Julia B <Jul***@discussions.microsoft.com> 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, 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 Show quoteHide quote "Alexey Smirnov" wrote: > On 3 Jul., 15:27, Julia B <Jul***@discussions.microsoft.com> 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) > 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 Show quoteHide quote "Alexey Smirnov" wrote: > On 3 Jul., 15:27, Julia B <Jul***@discussions.microsoft.com> 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) >
Other interesting topics
Referencing to LinkButton in Gridview TemplateField
Space or comment between the lines can affect the program Need Sr DOT NET Developer | Seatle,Washington | 2+ years Dynamic generation of a table When does IsReusable Property get interrogated? Deleting table row in table grid using ASP.NET MVC System.InvalidCastException was unhandled by user code double click reaches to inline code Custom PageHandler ??? User Control Error |
|||||||||||||||||||||||