locked
Binding two sets of data from a dropdownlist with a query RRS feed

  • Question

  • User-774280333 posted

    So, basically what <g class="gr_ gr_41 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" id="41" data-gr-id="41">i'm</g> trying to do is get two different values from a <g class="gr_ gr_55 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="55" data-gr-id="55">dropdownlist</g> that uses a <g class="gr_ gr_81 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="81" data-gr-id="81">datasource</g> and is inside a <g class="gr_ gr_143 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="143" data-gr-id="143">detailsview</g> and then I need to bind that data and use it in <g class="gr_ gr_252 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="252" data-gr-id="252">controlparameters</g>. I need both '<g class="gr_ gr_510 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="510" data-gr-id="510">movietitle</g>' and '<g class="gr_ gr_574 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="574" data-gr-id="574">movieid</g>'. I'm completely stumped and this and have like no idea how to do it. Any tips you could offer me would be amazing. 

    Code: 

    <asp:DetailsView ID="CustomerDetail"
    DataSourceID="moviedatasource" AutoGenerateRows="false"
    AutoGenerateInsertButton="true"
    AutoGenerateEditButton="true"
    AutoGenerateDeleteButton="true"
    EmptyDataText="No records."
    DataKeyNames="username" GridLines="Both"
    OnItemInserted="CustomerDetail_ItemInserted"
    OnItemInserting="CustomerDetail_ItemInserting"
    OnItemUpdated="CustomerDetail_ItemUpdated"
    OnItemUpdating="CustomerDetail_ItemUpdating"
    OnItemDeleted="CustomerDetail_ItemDeleted"
    runat="server">
    <HeaderStyle BackColor="Navy" ForeColor="White" />
    <RowStyle BackColor="White" />
    <AlternatingRowStyle BackColor="LightGray" />
    <EditRowStyle BackColor="LightCyan" />
    <Fields>
    <asp:BoundField DataField="UserName" Visible="False" HeaderText="username" InsertVisible="false" ReadOnly="true" SortExpression="username" />
    <asp:TemplateField HeaderText="MovieTitle" SortExpression="Movieid">
    <ItemTemplate>
    <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSourceW2" DataTextField="movieTitle" DataValueField="MovieId" SelectedValue='<%#Bind("movieID")%>' ></asp:DropDownList>
    <asp:SqlDataSource ID="SqlDataSourceW2" runat="server" ConnectionString="<%$ ConnectionStrings:Database1ConnectionString %>"
    ProviderName="<%$ ConnectionStrings:Database1ConnectionString.ProviderName %>"
    SelectCommand="SELECT [MovieID], [MovieTitle] FROM [movies_table] ORDER BY [Movietitle], [MovieID]"></asp:SqlDataSource>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="MovieTitle" HeaderText="MovieTitle" />
    <asp:BoundField DataField="MovieID" HeaderText="MovieID" />
    <asp:BoundField DataField="Rating" HeaderText="Rating" />
    <asp:BoundField DataField="Review" HeaderText="Review" />
    </Fields>
    </asp:DetailsView>

    <asp:SqlDataSource ID="moviedatasource"
    ConnectionString=
    "<%$ ConnectionStrings:Database1ConnectionString %>"
    ProviderName="<%$ ConnectionStrings:Database1ConnectionString.ProviderName %>"
    runat="server"
    SelectCommand="SELECT * FROM [review_table]
    WHERE ([UserName] = @UserName)"
    DeleteCommand="DELETE FROM [review_table]
    WHERE [UserName] = @UserName"
    InsertCommand="INSERT INTO [review_table] ([UserName],
    [movieid], [movietitle], [rating], [review])
    VALUES (@UserName, @movieid, @movietitle, @rating,
    @review)"
    UpdateCommand="UPDATE [review_table] SET [rating] = @rating,
    [review] = @review
    WHERE [UserName] = @UserName AND [Movieid] = @Title">
    <SelectParameters>
    <asp:SessionParameter Name="UserName" SessionField="UserName" Type="String" DefaultValue="VaderRox" />
    <asp:ControlParameter ControlID="CustomerDetail$DropDownList1" Name="Title" PropertyName="SelectedValue" />

    </SelectParameters>
    <DeleteParameters>
    <asp:SessionParameter Name="UserName" SessionField="UserName" Type="String" DefaultValue="VaderRox" />
    </DeleteParameters>
    <UpdateParameters>
    <asp:SessionParameter Name="UserName" SessionField="UserName" Type="String" DefaultValue="VaderRox" />
    <asp:Parameter Name="MovieTitle" Type="String" />
    <asp:Parameter Name="Movieid" Type="String" />
    <asp:Parameter Name="review" Type="String" />
    <asp:Parameter Name="rating" Type="String" />
    </UpdateParameters>
    <InsertParameters>
    <asp:SessionParameter Name="UserName" SessionField="UserName" Type="String" DefaultValue="VaderRox" />
    <asp:Parameter Name="MovieTitle" Type="String" />
    <asp:Parameter Name="Movieid" Type="String" />
    <asp:Parameter Name="review" Type="String" />
    <asp:Parameter Name="rating" Type="String" />
    </InsertParameters>
    </asp:SqlDataSource>

    Wednesday, May 9, 2018 9:40 PM

All replies

  • User-1716253493 posted

    For value use selectedvalue or selecteditem.value, for the text use selecteditem.text property

    property = "SelectedItem.Text"

    In design view, binding control inside a container is very hard, my idea is using two hiddenfield outside detailsview

    Use code behind ddl databound and ddl selectedindexchanged event to set the hiddenfields value

    hf_text.value = (ctype(sender,dropdownlist)).SeletedIndex.Text

    So, you can simply use the hiddenfield as controlparameter

    Wednesday, May 9, 2018 10:14 PM