Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Linqdatasource set values according to dropdownlist selection

Posted on 2010-11-21
12
Medium Priority
?
1,401 Views
Last Modified: 2013-11-11
Hi
I have a gridview that has a dropdown column, and regular text fields.
Both the gridview and dropdown are bound to their own separate linqdatasources.
The dropdown is in the first column.  
When a user selects the dropdown, I need to fill in a couple of the regular text fields in the same row.
I would be willing to unbind, change controls, whatever, in order to get this accomplished.

How can I provide such filtering?
Thanks
############# A TRY IN LINQ ROW INSERTING ################

    Protected Sub grdServiceDetails_RowInserting(ByVal sender As Object, ByVal e As TestWeb.GridViewInsertEventArgs) Handles grdServiceDetails.RowInserting
        Dim s As String = e.NewValues(0).ToString
        Dim d As String = e.NewValues(1).ToString
        Dim b As String = e.NewValues(2).ToString
        Dim c As String = e.NewValues(3).ToString

        Dim ddServ As DropDownList = DirectCast(Me.grdServiceDetails.InsertRow.FindControl("ddServiceOffered"), DropDownList)
        Dim tst As TestWeb.ExtendedGridView = Me.grdServiceDetails

        If ddServ Is Nothing Then

            ddServ = DirectCast(Me.grdServiceDetails.Rows(Me.grdServiceDetails.SelectedIndex).FindControl("ddServiceOffered"), DropDownList)
        End If


        Dim iServOffered As Integer = 0
        If Not ddServ Is Nothing Then
            If ddServ.SelectedIndex > -1 Then
                ' Dim gvRow As GridViewRow = DirectCast(ddServ.Parent.Parent, GridViewRow)

                iServOffered = ddServ.SelectedValue

                Dim dc As New SalonDataClassesDataContext
                Dim u As New SalonUtilities
                Dim sUser As String = u.CheckSessionAndReturnUser
                Dim q = (From a In dc.ServicesLUs Where a.UserID.ToString = sUser _
                         And a.LUServiceID = iServOffered Select a).FirstOrDefault
                If Not q Is Nothing Then
                    e.Row.Cells(2).Text = q.Describe
                    e.Row.Cells(3).Text = q.Price
                End If
            End If

        End If
    End Sub

############### A TRY IN DROPDOWN LIST #############

    Protected Sub ddServiceOffered_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
       
        '      e.Result.GetType()
        Dim ddServ As DropDownList = DirectCast(sender, DropDownList)
        'Dim value As String = Me.grdServiceDetails.Rows(row.RowIndex).Cells(0).Text
        'Session("value") = value
        Dim tst As TestWeb.ExtendedGridView = Me.grdServiceDetails
        Dim row As GridViewRow = DirectCast(ddServ.NamingContainer, GridViewRow)

        Dim txt As TextBox = DirectCast(tst.InsertRow.FindControl("txtDescribe"), TextBox)
        ' If Not txt Is Nothing Then
        Dim iServOffered As Integer = 0
        If Not ddServ Is Nothing Then
            If ddServ.SelectedIndex > -1 Then
                iServOffered = ddServ.SelectedValue
                'ddServ.DataBind
                Dim dc As New SalonDataClassesDataContext
                Dim u As New SalonUtilities
                Dim sUser As String = u.CheckSessionAndReturnUser
                Dim q = (From a In dc.ServicesLUs Where a.UserID.ToString = sUser _
                         And a.LUServiceID = iServOffered Select a).SingleOrDefault
                If Not q Is Nothing Then
                    If tst.InsertRowActive Then
                        tst.EnableViewState = True

                        ' ddServ.DataBind()
                        'If Not txt Is Nothing Then
                        '    txt.Text = q.Describe

                        'End If
                        tst.Rows(-1).Cells(2).Text = q.Describe
                        tst.Rows(0).Cells(3).Text = q.Price
                        'tst.DataBind()
                    End If
                    '  Me.grdServiceDetails.InsertRow.Cells.Item(3).Text = q.Describe
                    'Me.grdServiceDetails.InsertRow.Cells(3).Text = q.Price
                End If
            End If

        End If

        end if
        Dim ddServ As DropDownList = DirectCast(sender, DropDownList)

        'To get the row
        Dim gvRow As GridViewRow = DirectCast(ddServ.Parent.Parent, GridViewRow)
        Dim sPrice As String = ddServ.Items("Price").ToString
        Dim sDesc As String = ddServ.Items("Describe").ToString
        Dim ddlParent As DataControlFieldCell = DirectCast(ddServ.Parent, DataControlFieldCell)
        If ddServ.SelectedItem.Value > -1 Then
            Dim i As Integer = ddServ.SelectedValue
            ''I need the other control to change it's source
            Dim dc As New SalonDataClassesDataContext
            Dim u As New SalonUtilities
            Dim sUser As String = u.CheckSessionAndReturnUser
            Dim q = (From a In dc.ServicesLUs Where a.UserID.ToString = sUser _
                     And a.LUServiceID = i Select a)
            If Not q Is Nothing Then

            End If
        End If


    End Sub

################## ASPX ####################

           <cc1:ExtendedGridView ID="grdServiceDetails" 
                runat="server" AllowInserting="True" DataSourceID="LnqServiceDetails" DataKeyNames="ServiceDetailID,LUServiceID" 
              AutoGenerateColumns="False" AllowPaging="True" AllowSorting="True" 
              AscendingImageUrl="~/SortAsc.gif" BorderColor="Silver" CellPadding="4" 
              DescendingImageUrl="~/SortDesc.gif" ForeColor="#333333" PageSize="7" 
              ShowResultSummary="True" Width="100%" Font-Size="9pt" 
                  OnRowInserting="grdServiceDetails_RowInserting" >
                <PagerSettings Position="topAndBottom" />
                <Columns>
                    <asp:BoundField Visible="false" ControlStyle-CssClass="gridcontrol" 
                        ItemStyle-CssClass="gridrow" DataField="ServiceID" >
                        
                        <ControlStyle CssClass="gridcontrol"></ControlStyle>

                    <ItemStyle CssClass="gridrow"></ItemStyle>
                    </asp:BoundField>
                  <asp:TemplateField ControlStyle-CssClass="gridcontrol" 
                        ItemStyle-CssClass="gridrow" HeaderText="Service Type">
                  <ItemTemplate>
                 <%#Eval("ServicesLU.ServiceOffered")%>
    			</ItemTemplate>	         
              <EditItemTemplate>
                  <gdd:ExtendedDropDownList ID="ddServiceOffered" runat="server" DataSourceID="LnqServicesLU"
                     DataTextField="ServiceOffered" DataValueField="LUServiceID" 
                     OnSelectedIndexChanged="ddServiceOffered_SelectedIndexChanged" AutoPostBack="true"
                     SelectedValue='<%# Bind("LUServiceID") %>' >
                      
                  </gdd:ExtendedDropDownList>
              </EditItemTemplate>
              <InsertItemTemplate>
                  <gdd:ExtendedDropDownList ID="ddServiceOffered" runat="server" DataSourceID="LnqServicesLU"
                     DataTextField="ServiceOffered" DataValueField="LUServiceID" 
                     OnSelectedIndexChanged="ddServiceOffered_SelectedIndexChanged" AutoPostBack="true"
                     SelectedValue='<%# Bind("LUServiceID") %>' >
                      
                  </gdd:ExtendedDropDownList>
             </InsertItemTemplate>
              
              <ControlStyle BorderStyle="None" CssClass="gridcontrol" />

                <ItemStyle CssClass="gridrow" Width="20%"></ItemStyle>
                </asp:TemplateField>
                    <asp:BoundField Visible="true" ControlStyle-CssClass="gridcontrol" 
                        ItemStyle-CssClass="gridrow" DataField="Describe" >
                        
                        <ControlStyle CssClass="gridcontrol"></ControlStyle>

                    <ItemStyle CssClass="gridrow"></ItemStyle>
                    </asp:BoundField>

                
                
                    <asp:BoundField ControlStyle-CssClass="gridcontrol" 
                        ItemStyle-CssClass="gridrow" DataField="Price" HeaderText="Price" 
                        ApplyFormatInEditMode="True" DataFormatString="{0:C}" 
                        >
                    <ControlStyle CssClass="gridcontrol"></ControlStyle>

                    <ItemStyle CssClass="gridrow" Width="10%"></ItemStyle>
                    </asp:BoundField>
                    
                  <asp:TemplateField ControlStyle-CssClass="gridcontrol" 
                        ItemStyle-CssClass="gridrow" HeaderText="Formula">
                  <ItemTemplate>
                 <%#Eval("FormulasLU.FormulaName")%>
    			</ItemTemplate>	         
                      <EditItemTemplate>
                          <gdd:ExtendedDropDownList ID="ddFormula" runat="server" DataSourceID="LnqFormulasLU"
                             DataTextField="FormulaName" DataValueField="FormulaID" 
                             SelectedValue='<%# Bind("FormulaID") %>' >
                              
                          </gdd:ExtendedDropDownList>
                      </EditItemTemplate>
                      <ControlStyle BorderStyle="None" CssClass="gridcontrol" />

                    <ItemStyle CssClass="gridrow" Width="20%"></ItemStyle>
                    </asp:TemplateField>
                    <asp:ButtonField CommandName="FormulaView" Text="View Formula" />
                                     
                    <asp:CommandField HeaderText="Action" ShowDeleteButton="True" 
                        ShowEditButton="True" ShowHeader="True" ShowInsertButton="True">
                        <ControlStyle Font-Size="9pt" />
                    </asp:CommandField>
                </Columns>
                <FooterStyle CssClass="gridheader" />
                <RowStyle BackColor="#f9e6fb"  Font-Size="9pt" Font-Names="Verdana" />
                <EditRowStyle BackColor="#f9e604"  Font-Size="9pt" Font-Names="Verdana" />
                <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True"  Font-Size="9pt" ForeColor="#333333" />
                <PagerStyle HorizontalAlign="Center" Font-Size="8pt" Font-Names="Verdana" />
                <HeaderStyle BackColor="Purple" Font-Bold="True"  Font-Size="9pt" ForeColor="White" />
                <AlternatingRowStyle BackColor="White"  Font-Size="9pt" Font-Names="Verdana" />                                  
    			
                </cc1:ExtendedGridView>         
              <asp:LinqDataSource ID="LnqServicesLU" runat="server"
                  ContextTypeName="SalonDataClassesDataContext" OrderBy="ServiceOffered" 
                  TableName="ServicesLUs" Where="UserID == @UserID" OnSelected="LnqServicesLU_Selected">
                  <WhereParameters>
                      <asp:SessionParameter DbType="Guid" Name="UserID" SessionField="UserID" />
                  </WhereParameters>
              </asp:LinqDataSource>
                
              <asp:LinqDataSource ID="LnqFormulasLU" runat="server" 
                  ContextTypeName="SalonDataClassesDataContext" OrderBy="FormulaName" 
                  TableName="FormulasLUs" Where="UserID == @UserID">
                  <WhereParameters>
                      <asp:SessionParameter DbType="Guid" Name="UserID" SessionField="UserID" />
                  </WhereParameters>
              </asp:LinqDataSource>
              
              <asp:LinqDataSource ID="LnqServiceDetails" runat="server" 
                  ContextTypeName="SalonDataClassesDataContext" EnableDelete="True" 
                  EnableInsert="True" EnableUpdate="True" TableName="ServiceDetails" 
                  Where="ServiceID == @ServiceID">
                  <WhereParameters>
                      <asp:ControlParameter ControlID="txtServiceID" Name="ServiceID" 
                          PropertyName="Text" Type="Int32" />
                  </WhereParameters>
              </asp:LinqDataSource>

Open in new window

0
Comment
Question by:Sheritlw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
12 Comments
 
LVL 28

Expert Comment

by:strickdd
ID: 34190961
Create and OnSelectedIndexChanged even on the dropdown. Handle that event by pulling the data you need and updating that row in the GV to set the controls to the proper/new values.
0
 

Author Comment

by:Sheritlw
ID: 34191345
That's exactly what I did in my posted sample code.  I even tried using the linqdatasource inserting event.
Neither fills in the bound fields according the dropdown selection.

Thanks
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34204532
You can use a control parameter with the LINQDataSource that is used for the textboxes.

Check the code example here

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linqdatasource.whereparameters.aspx
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Sheritlw
ID: 34207459
Hi CodeCruiser,

I attached a screen shot of what I'm trying to do.
I have where parameters on both linqdatasources.
When someone selects an item from the dropdownlist, I need to fill the other cells with default values from the dropdownlists linqdatasource.
The gridview I am using is an extended gridview and the row index is -1, virtually non-existent.
I thought if I could insert the default values into the LinqDataSource from the dropdownlist selectedindexchanged event, then I might be able to figure out a way to get this to work.
If I need to change from the gridview to something else, that is fine.
I appreciate your help.
Thank you
0
 

Author Comment

by:Sheritlw
ID: 34207470
Forgot attachment DropDownList in Grid
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34208062
So you want default values in Description, Price, Qty, and Total columns? Where would the values come from?
0
 

Author Comment

by:Sheritlw
ID: 34209808
The linqdatasource that is bound to the dropdownlist contains the values.

Thanks
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 34211400
Trouble is that the LINQDataSource does not provide a way of retrieving values from the active record(in my knowledge). When you select an item from the dropdown list, does the page postback? If it does, you may have to write code to retrieve the values for selected item and put into the textboxes.
0
 

Author Comment

by:Sheritlw
ID: 34217866
Hi CodeCruiser,

I don't think I'm going to be able to find a solution for this using the standard grid with linq.
I am changing grids and going to use fpSpreads grid.  It will allow me to do what I need to do.
Thank you for your help.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34217889
Hi sheritlw,
Sorry for not being able to fix this for you but glad that you found a work around.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question