Improve company productivity with a Business Account.Sign Up

x
?
Solved

Linqdatasource set values according to dropdownlist selection

Posted on 2010-11-21
12
Medium Priority
?
1,423 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
  • 5
  • 4
10 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Free Data Recovery software is an advanced solution from Kernel Tools to recover data and files such as documents, emails, database, media and pictures, etc. It supports recovery from physical & logical drive after a hard disk crash, accidental/inte…

608 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