|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Understanding query stringsI 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. If you want the querystring to change, why don't you just use a
response.redirect to send the user to the same page, such as in the following: Response.Redirect('http://somewhere.com/servers.aspx?server=' & servernamevariable) If there is other information you want to keep, you can place them in a Session variable. If you need help in using querystrings, feel free to ask. Good Luck! Show quoteHide quote "Rickey Whitworth" <rickey@community.nospam> wrote in message news:ev1nvr0%23FHA.4028@tk2msftngp13.phx.gbl... >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. > 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" <rickey@community.nospam> microsoft.public.dotnet.framework.aspnet.webcontrols:31607| 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#FHA.4***@tk2msftngp13.phx.gbl> | 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 Show quoteHide quote | 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. | | | 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? Show quoteHide quote "Steven Cheng[MSFT]" <stch***@online.microsoft.com> wrote in message news:%23B99c95%23FHA.3764@TK2MSFTNGXA02.phx.gbl... > 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" <rickey@community.nospam> > | 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#FHA.4***@tk2msftngp13.phx.gbl> > | 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. > | > | > | > 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:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="CategoryName" DataValueField="CategoryID" OnDataBinding="DropDownList1_DataBinding" OnDataBound="DropDownList1_DataBound"> </asp:DropDownList> <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" <rickey@community.nospam> <#B99c95#FHA.3***@TK2MSFTNGXA02.phx.gbl>| References: <ev1nvr0#FHA.4***@tk2msftngp13.phx.gbl> | Subject: Re: Understanding query strings microsoft.public.dotnet.framework.aspnet.webcontrols:31633| 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: <ukGh3vD$FHA.***@TK2MSFTNGP15.phx.gbl> | 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 Show quoteHide quote | 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? | | "Steven Cheng[MSFT]" <stch***@online.microsoft.com> wrote in message | news:%23B99c95%23FHA.3764@TK2MSFTNGXA02.phx.gbl... | > 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" <rickey@community.nospam> | > | 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#FHA.4***@tk2msftngp13.phx.gbl> | > | 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. | > | | > | | > | | > | | | 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? Show quoteHide quote "Steven Cheng[MSFT]" <stch***@online.microsoft.com> wrote in message news:$qICBHH$FHA.832@TK2MSFTNGXA02.phx.gbl... > 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:DropDownList ID="DropDownList1" runat="server" > AutoPostBack="True" DataSourceID="SqlDataSource1" > DataTextField="CategoryName" DataValueField="CategoryID" > OnDataBinding="DropDownList1_DataBinding" > OnDataBound="DropDownList1_DataBound"> > </asp:DropDownList> > <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" <rickey@community.nospam> > | References: <ev1nvr0#FHA.4***@tk2msftngp13.phx.gbl> > <#B99c95#FHA.3***@TK2MSFTNGXA02.phx.gbl> > | 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: <ukGh3vD$FHA.***@TK2MSFTNGP15.phx.gbl> > | 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? > | > | "Steven Cheng[MSFT]" <stch***@online.microsoft.com> wrote in message > | news:%23B99c95%23FHA.3764@TK2MSFTNGXA02.phx.gbl... > | > 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" <rickey@community.nospam> > | > | 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#FHA.4***@tk2msftngp13.phx.gbl> > | > | 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. > | > | > | > | > | > | > | > > | > | > | > 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 I'm not sure about this behavior, if you're using the exact same page as I | 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? ============================= 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" <rickey@community.nospam> <#B99c95#FHA.3***@TK2MSFTNGXA02.phx.gbl> | References: <ev1nvr0#FHA.4***@tk2msftngp13.phx.gbl> <ukGh3vD$FHA.***@TK2MSFTNGP15.phx.gbl> <$qICBHH$FHA.***@TK2MSFTNGXA02.phx.gbl> | Subject: Re: Understanding query strings microsoft.public.dotnet.framework.aspnet.webcontrols:31738| 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#$FHA.3***@TK2MSFTNGP12.phx.gbl> | 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 Show quoteHide quote | 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? | | | "Steven Cheng[MSFT]" <stch***@online.microsoft.com> wrote in message | news:$qICBHH$FHA.832@TK2MSFTNGXA02.phx.gbl... | > 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:DropDownList ID="DropDownList1" runat="server" | > AutoPostBack="True" DataSourceID="SqlDataSource1" | > DataTextField="CategoryName" DataValueField="CategoryID" | > OnDataBinding="DropDownList1_DataBinding" | > OnDataBound="DropDownList1_DataBound"> | > </asp:DropDownList> | > <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" <rickey@community.nospam> | > | References: <ev1nvr0#FHA.4***@tk2msftngp13.phx.gbl> | > <#B99c95#FHA.3***@TK2MSFTNGXA02.phx.gbl> | > | 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: <ukGh3vD$FHA.***@TK2MSFTNGP15.phx.gbl> | > | 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? | > | | > | "Steven Cheng[MSFT]" <stch***@online.microsoft.com> wrote in message | > | news:%23B99c95%23FHA.3764@TK2MSFTNGXA02.phx.gbl... | > | > 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" <rickey@community.nospam> | > | > | 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#FHA.4***@tk2msftngp13.phx.gbl> | > | > | 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. | > | > | | > | > | | > | > | | > | > | > | | > | | > | | > | | | How do I pre-select items from a drop-down list when it is also databound?
Currently, I pre-select in the prerender event, because it wasn't working in the load event. Then I noticed that even though I was pre-selecting the value in the drop-down list, the gridview was not updated to reflect the change. So I also added this code dsLogicalLogView.Select(New UI.DataSourceSelectArguments()) This refreshes the sqldatasource and the gridview is updated when the page displays. But I wonder if this is causing the other problem I posted with the pager control? Show quoteHide quote "Steven Cheng[MSFT]" <stch***@online.microsoft.com> wrote in message news:%23B99c95%23FHA.3764@TK2MSFTNGXA02.phx.gbl... > 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" <rickey@community.nospam> > | 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#FHA.4***@tk2msftngp13.phx.gbl> > | 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. > | > | > | >
2.0 menu control and color
Dropdownlist: SelectedValue which is invalid VS2005 Designer does NOT display asp:panels!! Why? Coding issue Formview current Row contenteditable View State problem when multiple user work on the same page onload called only once Custom Buttons preserve password field over steps in wizard |
|||||||||||||||||||||||