Thanks for your followup Rickey,
For your two questions:
=============================
I do have one question. If you go to the page you
| created and pass a querystring, the page loads, the drop down item is
| selected and the gridview is populated. But in my test, if I then change
the
| querystring in the address bar and hit enter key, the new item is
selected
| in the drop down box, but the gridview is empty. If I hit refresh it
| appears. Is this by design?
=============================
I'm not sure about this behavior, if you're using the exact same page as I
pasted, this should be a browser related behavior since it run correctly on
myside (i've tested through both IE and firefox ...). And through the page
trace we can found that the GridView will perform databinding after the
DropDownList's databinding. The browser cache is also one possible cause,
but I feel strange that the dropdownlist change and the GridView not....
You can add some code to the Page_load and printout the timestamp to see
whether the page is actually rendered from serverside.....
=====================
Also, is there a way to make the querystring in the address bar change when
the drop-down list selected item changes? If not, the querystring is no
longer valid once a different item has been selected, meaning that if a
user
bookmarks the page, it will take them to the item in the querystring, not
the new item they selected. If the querystring cannot be changed, can it be
removed from the url after loading so that at least it want appear?
======================
I'm afraid this is a hard task for the page since url querystring is
somewhat a clientside setting (the user interactively specify the url...).
we can change the url, but should use clientside redirection like
Response.Redirect.... which I don't think is what you want. Also, this
is why my test page only use the Querystring when the page first time load
( in if(! IsPostBack) {...} )
Thanks,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Rickey Whitworth" <
[email protected]>
| References: <ev1nvr0#
[email protected]>
<#B99c95#
[email protected]>
<
[email protected]>
<
[email protected]>
| Subject: Re: Understanding query strings
| Date: Tue, 13 Dec 2005 07:38:45 -0600
| Lines: 273
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| Message-ID: <OXxztq#
[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| NNTP-Posting-Host: 66.182.150.119
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:31738
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
|
| Thank you for the response and the code sample. I believe this should
take
| care of my problem. I do have one question. If you go to the page you
| created and pass a querystring, the page loads, the drop down item is
| selected and the gridview is populated. But in my test, if I then change
the
| querystring in the address bar and hit enter key, the new item is
selected
| in the drop down box, but the gridview is empty. If I hit refresh it
| appears. Is this by design?
|
| Also, is there a way to make the querystring in the address bar change
when
| the drop-down list selected item changes? If not, the querystring is no
| longer valid once a different item has been selected, meaning that if a
user
| bookmarks the page, it will take them to the item in the querystring, not
| the new item they selected. If the querystring cannot be changed, can it
be
| removed from the url after loading so that at least it want appear?
|
|
| | > Thanks for your response Rickey,
| >
| > Seems the problem you met is specific to the pager, are you using the
| > default build-in paging of GridView? Also, does the code you used to
set
| > the dropdownlist's selected item the same as mine? Based on my local
| > test, using the page_load to assign the SelectedValue worked correctly
no
| > matter I used paging or not...... Anyway, here is my test page's code(I
| > also tested in master page scenaro......), you can have a test on your
| > side
| > to see whether it works....
| >
| >
| > I just use the "Product" and "Categories" table in NorthWind database
for
| > testing......
| > =========aspx=============
| > <div>
| > <asp:SqlDataSource ID="SqlDataSource1" runat="server"
| > ConnectionString="<%$ ConnectionStrings:LocalNorthWind %>"
| > SelectCommand="SELECT DISTINCT [CategoryID], [CategoryName]
| > FROM [Categories]"></asp:SqlDataSource>
| > <asp
ropDownList ID="DropDownList1" runat="server"
| > AutoPostBack="True" DataSourceID="SqlDataSource1"
| > DataTextField="CategoryName" DataValueField="CategoryID"
| > OnDataBinding="DropDownList1_DataBinding"
| > OnDataBound="DropDownList1_DataBound">
| > </asp
ropDownList>
| > <asp:SqlDataSource ID="SqlDataSource2" runat="server"
| > ConnectionString="<%$ ConnectionStrings:LocalNorthWind %>"
| > SelectCommand="SELECT [ProductName], [ProductID],
[CategoryID],
| > [Discontinued] FROM [Products] WHERE ([CategoryID] = @CategoryID)"
| > OnSelecting="SqlDataSource2_Selecting">
| > <SelectParameters>
| > <asp:ControlParameter ControlID="DropDownList1"
| > Name="CategoryID" PropertyName="SelectedValue"
| > Type="Int32" />
| > </SelectParameters>
| > </asp:SqlDataSource>
| > <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
| > AutoGenerateColumns="False"
| > DataKeyNames="ProductID" DataSourceID="SqlDataSource2"
| > PageSize="3" OnDataBinding="GridView1_DataBinding"
| > OnDataBound="GridView1_DataBound">
| > <Columns>
| > <asp:BoundField DataField="ProductName"
| > HeaderText="ProductName" SortExpression="ProductName" />
| > <asp:BoundField DataField="ProductID"
| > HeaderText="ProductID" InsertVisible="False"
| > ReadOnly="True" SortExpression="ProductID" />
| > <asp:BoundField DataField="CategoryID"
| > HeaderText="CategoryID" SortExpression="CategoryID" />
| > <asp:CheckBoxField DataField="Discontinued"
| > HeaderText="Discontinued" SortExpression="Discontinued" />
| > </Columns>
| > <PagerSettings Position="TopAndBottom" />
| > </asp:GridView>
| >
| > </div>
| >
| > =====code behind==========
| > public partial class ListGridView : System.Web.UI.Page
| > {
| > protected void Page_Load(object sender, EventArgs e)
| > {
| > if (!IsPostBack)
| > {
| > string cid = Request.QueryString["cid"];
| > if (cid != null && cid != string.Empty)
| > {
| > Trace.Warn("<br>DropDownList1.SelectedValue = cid;");
| > DropDownList1.SelectedValue = cid;
| >
| > }
| > }
| > }
| > protected void DropDownList1_DataBinding(object sender, EventArgs e)
| > {
| > Trace.Warn("<br>DropDownList1_DataBinding");
| > }
| > protected void DropDownList1_DataBound(object sender, EventArgs e)
| > {
| > Trace.Warn("<br>DropDownList1_DataBound");
| > }
| > protected void GridView1_DataBinding(object sender, EventArgs e)
| > {
| > Trace.Warn("<br>GridView1_DataBinding");
| > }
| > protected void GridView1_DataBound(object sender, EventArgs e)
| > {
| > Trace.Warn("<br>GridView1_DataBound");
| > }
| > protected void SqlDataSource2_Selecting(object sender,
| > SqlDataSourceSelectingEventArgs e)
| > {
| > Trace.Warn("SqlDataSource2_Selecting");
| > }
| > }
| >
| > ==============================
| >
| > Hope helps. Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure!
www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| >
| >
| >
| > --------------------
| > | From: "Rickey Whitworth" <
[email protected]>
| > | References: <ev1nvr0#
[email protected]>
| > <#B99c95#
[email protected]>
| > | Subject: Re: Understanding query strings
| > | Date: Thu, 8 Dec 2005 15:10:40 -0600
| > | Lines: 99
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| > | X-RFC2646: Format=Flowed; Original
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| > | Message-ID: <
[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| > | NNTP-Posting-Host: 66.182.150.119
| > | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP15.phx.gbl
| > | Xref: TK2MSFTNGXA02.phx.gbl
| > microsoft.public.dotnet.framework.aspnet.webcontrols:31633
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
| > |
| > | Thank you, that is what I was trying previously, but I thought it
might
| > be
| > | the wrong approach. It was working, then I started getting this error:
| > |
| > | An error has occurred because a control with id
| > | 'ctl00$ContentPlaceHolder1$GridView2$ctl04$ctl00' could not be
located
| > or
| > a
| > | different control is assigned to the same ID after postback. If the
ID
| > is
| > | not assigned, explicitly set the ID property of controls that raise
| > postback
| > | events to avoid this error.
| > |
| > | I added an @Trace directive to the page to identify which control
| > | ctl04$ctl100 was, and determined it was the pager control. If I
disable
| > | paging on the gridview, the problem goes away.
| > |
| > | The problem only happens in this situation:
| > | 1) I navigate to the page using a querystring (which then selects the
| > | appropriate value from the dropdown list)
| > | 2) I then select a different value from the drop down list
| > |
| > | the error says to explicitly set ids of controls that cause postback,
| > and
| > I
| > | assume a pager control causes postback, but how do I set its ID?
| > |
| > | | > | > Hi Rickey,
| > | >
| > | > For the GridView control, it can accept the filtering parameter only
| > from
| > | > single source(control or querystring...), so would still use the
| > | > DropDownList as the filtering control to change the GridView's
| > displaying
| > | > data when postback? If so, I think we'd better remain using the
| > | > Dropdownlist as the GridView's select parameter source.... And as
| > for
| > | > querystring , since we just use it to initialize the Dropdownlist
when
| > the
| > | > page first time load, so I think we can just manually add some code
to
| > | > parse the querystring and set the DropDownList's selected value in
| > | > Page_Load (when not postback....). For example:
| > | >
| > | > protected void Page_Load(object sender, EventArgs e)
| > | > {
| > | > if (!IsPostBack)
| > | > {
| > | > string cid = Request.QueryString["cid"];
| > | > if (cid != null && cid != string.Empty)
| > | > {
| > | > DropDownList1.SelectedValue = cid;
| > | > }
| > | > }
| > | > }
| > | >
| > | > Hope helps. Thanks,
| > | >
| > | > Steven Cheng
| > | > Microsoft Online Support
| > | >
| > | > Get Secure!
www.microsoft.com/security
| > | > (This posting is provided "AS IS", with no warranties, and confers
no
| > | > rights.)
| > | >
| > | > --------------------
| > | > | From: "Rickey Whitworth" <
[email protected]>
| > | > | Subject: Understanding query strings
| > | > | Date: Wed, 7 Dec 2005 10:25:19 -0600
| > | > | Lines: 17
| > | > | X-Priority: 3
| > | > | X-MSMail-Priority: Normal
| > | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| > | > | X-RFC2646: Format=Flowed; Original
| > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| > | > | Message-ID: <ev1nvr0#
[email protected]>
| > | > | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| > | > | NNTP-Posting-Host: 66.182.150.119
| > | > | Path:
| > TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| > | > | Xref: TK2MSFTNGXA02.phx.gbl
| > | > microsoft.public.dotnet.framework.aspnet.webcontrols:31607
| > | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
| > | > |
| > | > | I have a page with two web controls - a drop-down list of server
| > names
| > | > and a
| > | > | gridview that shows details about that server. The gridview is
using
| > the
| > | > | drop down list as a parameter, so changing the selected server in
| > the
| > | > | drop-down list causes a postback and the gridview updates to the
new
| > | > server.
| > | > |
| > | > | What I would like to do is add the ability to pass a querystring
to
| > the
| > | > page
| > | > | similar to the following:
| > | > |
| > | > |
http://somewhere.com/servers.aspx?server=server1
| > | > |
| > | > | so that when the page loads, server1 is pre-selected. I also want
| > the
| > | > | ability to change the server name once I get to the page if I
need
| > to.
| > | > |
| > | > | I thought about binding the gridview to the querystring, but I
| > cannot
| > | > figure
| > | > | out how to make the querystring change on postback.
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|