Gridview not working when trying to use Select Parameters and a Master page

Last post 01-11-2008 11:52 AM by robertwboykin. 6 replies.

Sort Posts:

  • Gridview not working when trying to use Select Parameters and a Master page

    11-03-2006, 11:04 AM
    • Loading...
    • wmolde
    • Joined on 10-11-2006, 2:51 PM
    • Colorado
    • Posts 13

    Hi, I am trying to to use a gridview that is sorted by a DropDownList.  Everything works 100% until I take all of my code (the DropDown List, Gridview, and related ObjectDataSources) and place it in a container to be used in conjunction with a Master page.  At this time the gridview will no longer sort based off of the DropDownList.  I've set break points and the data is being re-bound when the DropDownList selection has been changed, but the gridview does not seem to notice the FormParamter (dropDownList value) that is being passed to it.  It does not sort by any of the values in the DropDownList, it simply returns all entries in the database. (the passed parameter is optional to my SQL Query)  I have attempted to manually re-bind the data, removed all update panels, changed update panel triggers...  I'm out of ideas!  I have re-created this problem with different pages and different datasets and I get the same results, my code is as follows:

    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="selSeverity" DataTextField="Name" DataValueField="ID" />

     

    <asp:ObjectDataSource ID="selSeverity" runat="server" OldValuesParameterFormatString="original_{0}"

     

    SelectMethod="GetData" TypeName="Sel_SeverityTableAdapters.SeverityList_SelectTableAdapter">

     

    </asp:ObjectDataSource>

     

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SearchResults">

     

    <Columns>

     

    <asp:BoundField DataField="BugTitle" HeaderText="BugTitle" SortExpression="BugTitle" />

     

    <asp:BoundField DataField="SelSeverity" HeaderText="SelSeverity" SortExpression="SelSeverity" />

     

    <asp:BoundField DataField="SelStatus" HeaderText="SelStatus" SortExpression="SelStatus" />

     

    <asp:BoundField DataField="SubmittedDate" HeaderText="SubmittedDate" SortExpression="SubmittedDate" />

     

    <asp:BoundField DataField="ProjectName" HeaderText="ProjectName" SortExpression="ProjectName" />

     

    <asp:BoundField DataField="AssignedToFullName" HeaderText="AssignedToFullName" ReadOnly="True" SortExpression="AssignedToFullName" />

     

    <asp:BoundField DataField="SubmittedByFullName" HeaderText="SubmittedByFullName" ReadOnly="True" SortExpression="SubmittedByFullName" />

     

    <asp:BoundField DataField="SelCategory" HeaderText="SelCategory" SortExpression="SelCategory" />

     

    <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" SortExpression="ID" />

     

    </Columns>

     

    </asp:GridView>

     

    <asp:ObjectDataSource ID="SearchResults" runat="server" OldValuesParameterFormatString="original_{0}"

     

    SelectMethod="GetData" TypeName="Bug_SearchTestTableAdapters.Bug_SearchTest_SelectTableAdapter">

     

    <SelectParameters>

     

    <asp:FormParameter FormField="DropDownList1" Name="Severity" Type="Object" />

     

    </SelectParameters>

     

    </asp:ObjectDataSource>

    This code will work if I paste it into a empty page.  But if I place it inside of a <ASP:Content> situation so that I can use it with a Master Page, the gridview fails to see the passed parameters.  Any Ideas?

    Thanks in advance for the help!
    Justin

     

  • Re: Gridview not working when trying to use Select Parameters and a Master page

    11-04-2006, 9:17 AM
    Answer
    • Loading...
    • jason2k
    • Joined on 11-04-2006, 1:36 PM
    • Posts 2

    I have similiar problem just that my gridview only sorts in the ascending order for the particular column. I have done a few debugging and tracing and found out that the gridview somehow 'forgets' its current SortExpression.

    Step 0 : No column is being sorted yet. Therefore the SortExpression of the gridview will return an empty string. The SortDirection of the gridview will return 'Ascending'.

    Step 1 : I click on a column header to initiate a sort for that column. Since this is the first time I click on the column header, the column should be sorted in the ascending order. The expected SortExpression of the gridview now should be the column name and the SortDirection should be 'Ascending'
     
    Step 2 : Yes, the column is being sorted in the ascending order as expected. However, as soon as the column is being sorted, the SortExpression of the gridview is resetted to an empty string and the SortDirection is 'Ascending'.

    Step 3 : I click on the same column header again which now should be sorted in the descending order. However, since the SortExpression has been resetted to an empty string in Step 2, the column will be sorted in the ascending order again as if this is the first time I click on the column header.

    Then the steps repeat all over again.

    I only face this problem when I'm using the gridview in conjunction with a master page. I do not have this problem when I'm using it on normal web pages without a master page.

     
    Here is what I know and suspcect. When I checked the HTML codes that is returned from the webserver,
    the id of my gridview has been changed to MasterPageID_ContentPlaceHolderID_myGridViewID.
    If I din assign my master page an ID, then it will generate a 'ctl00' as the id for the master page.
    If I assign 'title' and 'gvItems' as the id of my contentplaceholder and gridview respectively, then the HTML id that I will get is 'ctl00_title_gvItems'.

    ASP .NET will generate Unique client ID for the controls on the webpage which has 'runat="server"' as their attribute. If the control is nested in another control, then ASP .NET will create an ID preceded with the id of the parents of the controls delimited with an underscore. For example parentID1_parentID2_ControlID. In this example ControlID is nested within parentID2 which in turn is nested within parentID1.

    The above is how ASP.NET create an 'id' for controls. ASP .NET adopts the same naming convention in creating a 'name' for a control just that the delimiter is a dollar sign instead of an underscore. For example of the above case, the name of the control would be parentID1$parentID2$ControlID.

    For web server controls like gridview, ASP .NET will only generate an id for it. There won't be any name for that control.

    When I hover over a column header, I got the link location something like 'javascript:__doPostBack('ctl00$title$gvItems','Sort$CreateDate')'
    We can clearly see that the first argument of the function doPostBack is the 'name' of my gridview. But my gridview does not have a name attribute. It only has an id attribute which is 'ctl00_title_gvItems'. I think here is where everything gone wrong.
     

  • Re: Gridview not working when trying to use Select Parameters and a Master page

    11-06-2006, 5:21 PM
    • Loading...
    • wmolde
    • Joined on 10-11-2006, 2:51 PM
    • Colorado
    • Posts 13

    I looked into my code and the issues appear to be very simular.  However my gridview is attempting to update off of a different object, not a link inside of the gridview.  When looking in the returned HTML for the page I noticed that my gridview was not given a 'name' as well.  The control however that is calling the PostBack to refresh my gridview is the dropdownlist, which has both a 'name' and 'id'.  I think that the lack of name on the gridview is not the primary issue here.  I loaded the code that I provided into an empty page (which allowed everything to work as expected) and noticed that the gridview (table) definition did not have the 'name' specified in it either.  Since everything works in this case, and the table definitions are the same I think the issue might be elsewhere.  In fact other than the name appending all of the location information, 'ctl00$bodyContent$DropDownList1', there is very little difference in the main page compnents.  What I did noticed though was a glob of javascript that was included in the working file that was not included in the other file. It is as follows:

    <script src="http://forums.asp.net/BugTracking/WebResource.axd?d=xER6uzMVgC0CjMbAy3Sdzg2&amp;t=632972033091650934" type="text/javascript"></script>

    <script src="http://forums.asp.net/BugTracking/WebResource.axd?d=MtRLmQXxLFViobZzuCdnx2gmF_PpuIdbJ4yvaZ9Ah_w4ZUT3h6Gxh64C9hOQpJ3HjzvjOaP3BlYPdV-oiPSaxP_W76cMvy3yJRE3At0rCbibSJH5KUTD_DfE-1Un0uYe_ovMYo1UFP2lIqrHr17MIkWLYIRavXhzaS3qwnkWuzQ1&amp;t=632972055765973075" type="text/javascript"></script>
    <script src="http://forums.asp.net/BugTracking/WebResource.axd?d=MtRLmQXxLFViobZzuCdnx2gmF_PpuIdbJ4yvaZ9Ah_w4ZUT3h6Gxh64C9hOQpJ3HjzvjOaP3BlYPdV-oiPSaxP_W76cMvy3yJRE3At0rCbibSJH5KUTD_DfE-1Un0uYeVvloxYD8J74yL5bZd7ieAE5DYseVYQMweXhRdSFUO641&amp;t=632972055765973075" type="text/javascript"></script>
        <script type="text/javascript">
    Sys.WebForms.PageRequestManager._initialize('ScriptManager1', document.getElementById('form1'));
    Sys.WebForms.PageRequestManager.getInstance()._updateControls([], [], [], 90);
    </script>
     

    In my relativly uneducated guess it seems like the "Sys.WebForms.PageRequestManager._initialize" might have something to do with the gridview not 'seeing' when a selection is changed.  Anyone out there have an idea as to how to get aroudnthis issue?

     

    Thanks! Justin

  • Re: Gridview not working when trying to use Select Parameters and a Master page

    11-14-2006, 12:20 PM
    Answer
    • Loading...
    • wmolde
    • Joined on 10-11-2006, 2:51 PM
    • Colorado
    • Posts 13

    I finally found a solution to this issue... For anyone who might find themselves with the same issue:

    The issue seems to be with the <asp:formparameter>/<asp:sessionparameter>, they just don't work when using a gridview in conjuncture with a master page.  So what needs to be done is to change the asp:formparameters to asp:controlparameters.  Once I did this everything began to work as I wanted it to, I don't know why but it works.

  • Re: Gridview not working when trying to use Select Parameters and a Master page

    12-05-2006, 11:20 AM
    • Loading...
    • heathers
    • Joined on 11-02-2006, 3:52 PM
    • Posts 46
    Thanks for posting back result, saved me a lot of grief!! :)
  • Re: Gridview not working when trying to use Select Parameters and a Master page

    01-18-2007, 5:43 AM
    • Loading...
    • glasenic
    • Joined on 10-25-2006, 6:54 AM
    • Posts 4

    Hello,

    I'm having the same problem with sorting the gridview. When I click twice on a column to sort it doesn't change the sort order.

    I'm not using a SQLDataSource but a DataTable so I can't use the trick with the controlparameters.

    Before I switched to Masterpages everything worked fine with the Gridview.

     Do you have any ideas?

    Thanks in advance!!!
     

  • Re: Gridview not working when trying to use Select Parameters and a Master page

    01-11-2008, 11:52 AM

    I also am now having a very similar issue.  I have a GridView set up against my datasource which is selecting from a table based on a session parameter.  Instead of using the select statement in the datasource, the gridview displays all the information from the table.

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
    <Columns>
    <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
    <asp:BoundField DataField="dateOfBirth" HeaderText="dateOfBirth" SortExpression="dateOfBirth" />
    </Columns>
    </asp:GridView>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:robertw_sigmaUsersConnectionString %>" SelectCommand="SELECT [name], [dateOfBirth] FROM [characters] WHERE (Email = @email)">
    <SelectParameters>
    <asp:SessionParameter Name="email" SessionField="Email" Type="String" />
    </SelectParameters>
    </asp:SqlDataSource>

Page 1 of 1 (7 items)
Microsoft Communities
Page view counter