Monday, March 26, 2012

is this possible?

Can this be done on asp.net 2.0??

<asp:SqlDataSource id="SqlDataSource2" runat="server" connectionstring="<%$ ConnectionStrings:BonsaiDataBaseConnectionString %>" selectcommand="SELECT [Nederlandse Naam] AS Nederlandse_Naam FROM [BonsaiSoorten]WHERE [Botanische Naam]=' <% DDL1.SelectedItem.Value%> ' ">
</asp:SqlDataSource>

I don't think that's possible, but you could use a ControlParameter in the SelectParameters property of the SqlDataSource to do that.

HTH,
Ryan

|||You can do the following instead (example using TableMaster and TableDetail with MasterId in common):

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1"
DataTextField="Description" DataValueField="MasterId">
</asp:DropDownList
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
SelectCommand="SELECT * FROM [TableMaster]"></asp:SqlDataSource
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="DetailId"
DataSourceID="SqlDataSource2">
<Columns>
<asp:BoundField DataField="DetailId" HeaderText="DetailId" ReadOnly="True" SortExpression="DetailId" />
<asp:BoundField DataField="MasterId" HeaderText="MasterId" SortExpression="MasterId" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
</Columns>
</asp:GridView
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
SelectCommand="SELECT * FROM [TableDetail] WHERE ([MasterId] = @.MasterId)">
<SelectParameters>
<asp:ControlParameterControlID="DropDownList1" Name="MasterId" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
|||Thanks for your quick reply!!

Can this value be added to a label?? I tried several things but nothing worked out.|||What value? Please be more specific, providing code where applicable.|||I've got a table in a database with two rows, a 'botanic name tree' and a 'dutch name tree' column. The dropdownlist is filled with the values of the 'botanic name tree' column. When a value is selected I like to show the correspondending value of the 'dutch name tree' column, in the same row as the selected botanic name, in a label.

Now I've got this working with your code in combination with two dropdownlists. Now I like to use it with a dropdownlist and a label.|||Provide a sample code if possible. I still can't visualize what it is that you're trying to achieve. I assume that you're still using a GridView control where you want to have a DDL as one of the columns along with a Label, right? Providing a sample code will make it much more clear.|||It's all upside down already. I wasn't using a Gridview. I got a ddl with a label and I wanted to change the label.text property with the correspondending value (in the database) of the selected value in the ddl.

It's hard for me to explain in english and I don't have the code anymore because I was trying to get it to work. I've got now new ideas to get my page done and the issues I'm walking against are totally different so when I have a new question I post it in a new thread.

Thanks for your replies and patience.sql

No comments:

Post a Comment