Click to See Complete Forum and Search --> : Use querystring and/or controlparameter in sqlDataSource


JohanVeldkamp
04-28-2011, 09:49 AM
Hi There,
I have a new question for you.

In a page I have a Gridview with a list of items. In the link of the items I have 2 parameters as querystring. The first parameter let the treecontrol on the next page makes the tree. The other parameter is used as the start parameter of tree. Till so far no questions.
In the same page as the tree, there is a DetailsView. This DetailsView has now a DefaultValue in the ControlValue from 1. The ControlValue depends after the first click on the TreeView. But when you first come in to the page, the DefaultValue has to be one of the Querystring values from the previous page.

example:
firstpage
item1 &parent=1&hoofdid=200
item2 &parent=2&hoofdid=400
item3 &parent=3&hoofdid=700
etc.

After you click the first items
Nextpage
treeview because of parent=1 and startpoint is hoofdid=200
The default value on the nextpage at the firsttime is always 1 and that is not the good one for each tree, that must be hoofdid querystring parameter from the previouspage.


<asp:DetailsView ID="DetailsView1" runat="server"
AutoGenerateRows="False" DataKeyNames="WetTekst_Id" DataSourceID="ShowWetsItem">
<Fields>
<asp:BoundField DataField="WetTekst_Titel" HeaderText="WetTekst_Titel" ShowHeader="false"
SortExpression="WetTekst_Titel" />
<asp:BoundField DataField="WetTekst_Omschrijving" ShowHeader="false"
HeaderText="WetTekst_Omschrijving" SortExpression="WetTekst_Omschrijving"
HtmlEncode="False" HtmlEncodeFormatString="False" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="ShowWetsItem" runat="server"
ConnectionString="<%$ ConnectionStrings:BouwgegevensConnectionString %>"
SelectCommand="SELECT [WetTekst_Id], [WetTekst_Titel], [WetTekst_Omschrijving] FROM [tbWetTekst] WHERE ([WetTekst_Id] = @WetTekst_Id)">
<SelectParameters>
<asp:ControlParameter ControlID="LeftContentPlaceHolder$WettenTree" DefaultValue="1"
Name="WetTekst_Id" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>


Can anyone help me solving this problemn, the treeview is build in the codebehind.

Greet and many thanks allready,
Johan

Ribeyed
04-28-2011, 07:53 PM
Hi,

You get the value from the querystring:


Request.QueryString("hoofdid")


So try:


asp:DetailsView ID="DetailsView1" runat="server"
AutoGenerateRows="False" DataKeyNames="WetTekst_Id" DataSourceID="ShowWetsItem">
<Fields>
<asp:BoundField DataField="WetTekst_Titel" HeaderText="WetTekst_Titel" ShowHeader="false"
SortExpression="WetTekst_Titel" />
<asp:BoundField DataField="WetTekst_Omschrijving" ShowHeader="false"
HeaderText="WetTekst_Omschrijving" SortExpression="WetTekst_Omschrijving"
HtmlEncode="False" HtmlEncodeFormatString="False" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="ShowWetsItem" runat="server"
ConnectionString="<%$ ConnectionStrings:BouwgegevensConnectionString %>"
SelectCommand="SELECT [WetTekst_Id], [WetTekst_Titel], [WetTekst_Omschrijving] FROM [tbWetTekst] WHERE ([WetTekst_Id] = @WetTekst_Id)">
<SelectParameters>
<asp:ControlParameter ControlID="LeftContentPlaceHolder$WettenTree" DefaultValue="<%= Request.QueryString("hoofdid")%>"
Name="WetTekst_Id" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>


regards

Ribs

JohanVeldkamp
05-02-2011, 02:39 AM
Hi There,

I tried your sollution to put the request.querystring into the defaultvalue, but this gives an runtime error.


Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>