This is a migrated thread and some comments may be shown as answers.

NeedDataSource based on combobox SelectedValue

9 Answers 300 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ida
Top achievements
Rank 1
Ida asked on 18 Nov 2013, 11:28 AM

Hi,

I have a RadGrid that binds using NeedDataSource. The NeedDataSource calls a tableadapter that uses a combobox SelectedValue as an input parameter. So the grid is populated based on the SelectedValue.

That works fine when the page first loads. Though I am having issues with when I change a combobox SelectedValue.

I believe it is a matter of the event ordering. As in the NeedDataSource kicks off BEFORE the SelectedIndexChanged is fired.

Below is my RadGrid:


<telerik:RadGrid ID="RDHauls" runat="server" AutoGenerateEditColumn="True" GridLines="Horizontal" AutoGenerateColumns="False" AlternatingItemStyle-BackColor="#ecf3f4" BorderColor="#28899A" EditItemStyle-BackColor="#009999" EditItemStyle-Font-Bold="true" OnItemDataBound="RDHauls_ItemDataBound" OnItemCreated="RDHauls_ItemCreated" OnNeedDataSource="RDHauls_NeedDataSource" CssClass="Radgrid">
          <AlternatingItemStyle BackColor="#ECF3F4"></AlternatingItemStyle>
          <HeaderStyle BorderColor="#28899A" Font-Bold="True" Font-Size="12px" Font-Names="Verdana" />
             <MasterTableView EnableViewState="false">
                   <Columns>
                       <telerik:GridBoundColumn DataField="TripCode" FilterControlAltText="Filter TripCode column" HeaderText="Trip Code" SortExpression="TripCode" UniqueName="TripCode" ReadOnly="true"></telerik:GridBoundColumn>
                       <telerik:GridBoundColumn DataField="VessReg"  FilterControlAltText="Filter VessReg column" HeaderText="Vessel" SortExpression="VessReg" UniqueName="VessReg" ReadOnly="true"></telerik:GridBoundColumn>
                       <telerik:GridBoundColumn DataField="HaulNumber" HeaderText="Haul" UniqueName="HaulNumber" ReadOnly="true"></telerik:GridBoundColumn>
                       <telerik:GridBoundColumn DataField="RigNumber" HeaderText="Rig"  UniqueName="RigNumber" ReadOnly="true"></telerik:GridBoundColumn>
                       <telerik:GridDropDownColumn DataField="Technique" HeaderText="Technique" ListTextField="Name" ListValueField="Code" UniqueName="Technique" ColumnEditorID="Technique" Visible="false" DropDownControlType="DropDownList"></telerik:GridDropDownColumn>
                       <telerik:GridCheckBoxColumn DataField="HaulSampledTrueFalse" HeaderText="Haul Sampled?" Visible="false" UniqueName="HaulSampledTrueFalse" ColumnEditorID="HaulSampled"></telerik:GridCheckBoxColumn>
                       <telerik:GridCheckBoxColumn DataField="TowDisruptedTrueFalse" HeaderText="Tow Disrupted?" Visible="false" UniqueName="TowDisruptedTrueFalse"></telerik:GridCheckBoxColumn>
                       <telerik:GridBoundColumn DataField="CodEnd" HeaderText="Cod End (mm)" UniqueName="CodEnd" ColumnEditorID="CodEnd" Visible="false" ConvertEmptyStringToNull="true"></telerik:GridBoundColumn>
                       <telerik:GridBoundColumn DataField="MeshSize" HeaderText="Mesh Size (mm)" UniqueName="MeshSize" Visible="false"></telerik:GridBoundColumn>
                       <telerik:GridBoundColumn DataField="SelectivityMesh" HeaderText="Selectivity Mesh (mm)" UniqueName="SelectivityMesh" Visible="false"></telerik:GridBoundColumn>                
                       <telerik:GridDropDownColumn DataField="TwineCode" HeaderText="Twine" ListTextField="Name" ListValueField="Code" UniqueName="TwineCode" ColumnEditorID="TwineCode" Visible="false" DropDownControlType="DropDownList"></telerik:GridDropDownColumn>                     
                       <telerik:GridBoundColumn DataField="TwineThickness" HeaderText="Twine Thickness (mm)" UniqueName="TwineThickness" Visible="false" DataType="System.Decimal"></telerik:GridBoundColumn>
                       <telerik:GridDropDownColumn DataField="GroundGear" HeaderText="Ground Gear" ListTextField="Name" ListValueField="Code" UniqueName="GroundGear" ColumnEditorID="GroundGear" Visible="false" DropDownControlType="DropDownList"></telerik:GridDropDownColumn>  
                       <telerik:GridBoundColumn DataField="Bridal" HeaderText="Bridal (m)" UniqueName="Bridal" Visible="false" DataType="System.Int32"></telerik:GridBoundColumn>
                       <telerik:GridBoundColumn DataField="HeadlineHeight" HeaderText="Headline Height (m)" UniqueName="HeadlineHeight" Visible="false"></telerik:GridBoundColumn>
                       <telerik:GridBoundColumn DataField="WarpLength" HeaderText="Warp Length (fath)" UniqueName="WarpLength" Visible="false"></telerik:GridBoundColumn>
                       <telerik:GridBoundColumn DataField="DoorSpread" HeaderText="Door Spread (m)" UniqueName="DoorSpread" Visible="false"></telerik:GridBoundColumn>
                       <telerik:GridDropDownColumn DataField="TidalStateCode" HeaderText="Tidal State" ListTextField="Name" ListValueField="Code" UniqueName="TidalStateCode" ColumnEditorID="TidalStateCode" Visible="false" DropDownControlType="DropDownList"></telerik:GridDropDownColumn>     
                       <telerik:GridDropDownColumn DataField="TidalStrengthCode" HeaderText="Tidal Strength" ListTextField="Name" ListValueField="Code" UniqueName="TidalStrengthCode" ColumnEditorID="TidalStrengthCode" Visible="false" DropDownControlType="DropDownList"></telerik:GridDropDownColumn>                 
                       <telerik:GridDropDownColumn DataField="TidalDirectionCode" HeaderText="Tidal Direction" ListTextField="Name" ListValueField="Code" UniqueName="TidalDirectionCode" ColumnEditorID="TidalDirectionCode" Visible="false" DropDownControlType="DropDownList"></telerik:GridDropDownColumn
                       <telerik:GridBoundColumn DataField="GroundSpeed" HeaderText="Speed Over Ground (kts)" UniqueName="GroundSpeed" Visible="false" DataType="System.Decimal"></telerik:GridBoundColumn>
                       <telerik:GridBoundColumn DataField="ShotDate" HeaderText="Shot Date" UniqueName="ShotDate" Visible="false">
                        <ColumnValidationSettings EnableRequiredFieldValidation="True">
                                <RequiredFieldValidator ID="RFShotDate" Font-Bold="True"> Enter Shot date</RequiredFieldValidator>
                            </ColumnValidationSettings>
                       </telerik:GridBoundColumn>
                       <telerik:GridDropDownColumn DataField="ShotTime" HeaderText="Shot Time" ListTextField="vchTime" ListValueField="vchTime" UniqueName="ShotTime" ColumnEditorID="ShotTime" Visible="false" DropDownControlType="DropDownList"></telerik:GridDropDownColumn
                       <telerik:GridBoundColumn DataField="ShotDepth" HeaderText="Shot Depth (fath)" UniqueName="ShotDepth" Visible="false" DataType="System.Decimal"></telerik:GridBoundColumn>
                       <telerik:GridBoundColumn DataField="ShotLatd" HeaderText="Shot Latitude (deg)" UniqueName="ShotLatd" Visible="false">
                          <ColumnValidationSettings EnableRequiredFieldValidation="True">
                                <RequiredFieldValidator ID="RFShotLatitudeD" Font-Bold="True"> Enter Shot Latitude (deg)</RequiredFieldValidator>
                            </ColumnValidationSettings>
                       </telerik:GridBoundColumn>
                       <telerik:GridBoundColumn DataField="ShotLatm" HeaderText="Shot Latitude (min)" UniqueName="ShotLatm" Visible="false">
                          <ColumnValidationSettings EnableRequiredFieldValidation="True">
                                <RequiredFieldValidator ID="RFShotLatitudeM" Font-Bold="True"> Enter Shot Latitude (min)</RequiredFieldValidator>
                            </ColumnValidationSettings>
                       </telerik:GridBoundColumn>
                       <telerik:GridBoundColumn DataField="ShotLond" HeaderText="Shot Longitude (deg)" UniqueName="ShotLond" Visible="false">
                         <ColumnValidationSettings EnableRequiredFieldValidation="True">
                                <RequiredFieldValidator ID="RFShotLongitudeD" Font-Bold="True"> Enter Shot Longitude (deg)</RequiredFieldValidator>
                            </ColumnValidationSettings>
                       </telerik:GridBoundColumn>
                       <telerik:GridBoundColumn DataField="ShotLonm" HeaderText="Shot Longitude (min)" UniqueName="ShotLonm" Visible="false">
                          <ColumnValidationSettings EnableRequiredFieldValidation="True">
                                <RequiredFieldValidator ID="RFShotLongitudeM" Font-Bold="True"> Enter Shot Longitude (min)</RequiredFieldValidator>
                            </ColumnValidationSettings>
                       </telerik:GridBoundColumn>
                       <telerik:GridTemplateColumn UniqueName="ShotEastWest" ColumnEditorID="ShotEastWest" HeaderText="Shot East/West" Visible="false">
                           <ItemTemplate>
                               <%# Eval("ShotEW")%>
                           </ItemTemplate>
                           <EditItemTemplate>
                               <asp:RadioButtonList ID="rdShotEastWest" runat="server" RepeatDirection="Horizontal"
                                  <asp:ListItem Text="East" Value="2"></asp:ListItem>
                                  <asp:ListItem Text="West" Value="1"></asp:ListItem>
                               </asp:RadioButtonList>
                           </EditItemTemplate>
                       </telerik:GridTemplateColumn>
                        <telerik:GridBoundColumn DataField="HaulDate" HeaderText="Haul Date" UniqueName="HaulDate" Visible="false">
                            <ColumnValidationSettings EnableRequiredFieldValidation="True">
                                <RequiredFieldValidator ID="RFHaulDate" Font-Bold="True"> Enter Haul date</RequiredFieldValidator>
                            </ColumnValidationSettings>
                       </telerik:GridBoundColumn>
                       <telerik:GridDropDownColumn DataField="HaulTime" HeaderText="Haul Time" ListTextField="vchTime" ListValueField="vchTime" UniqueName="HaulTime" ColumnEditorID="HaulTime" Visible="false" DropDownControlType="DropDownList"></telerik:GridDropDownColumn>   
                       <telerik:GridBoundColumn DataField="HaulDepth" HeaderText="Haul Depth (fath)" UniqueName="HaulDepth" Visible="false" DataType="System.Decimal"></telerik:GridBoundColumn>
                       <telerik:GridBoundColumn DataField="HaulLatd" HeaderText="Haul Latitude (deg)" UniqueName="HaulLatd" Visible="false">
                         <ColumnValidationSettings EnableRequiredFieldValidation="True">
                                <RequiredFieldValidator ID="RFHaulLatitudeD" Font-Bold="True"> Enter Haul Latitude (deg)</RequiredFieldValidator>
                            </ColumnValidationSettings>
                       </telerik:GridBoundColumn>
                       <telerik:GridBoundColumn DataField="HaulLatm" HeaderText="Haul Latitude (min)" UniqueName="HaulLatm" Visible="false">
                          <ColumnValidationSettings EnableRequiredFieldValidation="True">
                                <RequiredFieldValidator ID="RFHaulLatitudeM" Font-Bold="True"> Enter Haul Latitude (min)</RequiredFieldValidator>
                            </ColumnValidationSettings>                       
                       </telerik:GridBoundColumn>
                       <telerik:GridBoundColumn DataField="HaulLond" HeaderText="Haul Longitude (deg)" UniqueName="HaulLond" Visible="false">
                           <ColumnValidationSettings EnableRequiredFieldValidation="True">
                                <RequiredFieldValidator ID="RFHaulLongitudeD" Font-Bold="True"> Enter Haul Longitude (deg)</RequiredFieldValidator>
                            </ColumnValidationSettings>    
                       </telerik:GridBoundColumn>
                       <telerik:GridBoundColumn DataField="HaulLonm" HeaderText="Haul Longitude (min)" UniqueName="HaulLonm" Visible="false">
                          <ColumnValidationSettings EnableRequiredFieldValidation="True">
                                <RequiredFieldValidator ID="RFHaulLongitudeM" Font-Bold="True"> Enter Haul Longitude (min)</RequiredFieldValidator>
                            </ColumnValidationSettings>
                       </telerik:GridBoundColumn>
                       <telerik:GridTemplateColumn UniqueName="HaulEastWest" ColumnEditorID="HaulEastWest" HeaderText="Haul East/West" Visible="false">
                           <ItemTemplate>
                               <%# Eval("HaulEW")%>
                           </ItemTemplate>
                           <EditItemTemplate>
                               <asp:RadioButtonList ID="rdHaulEastWest" runat="server" RepeatDirection="Horizontal">
                                   <asp:ListItem Text="East" Value="2"></asp:ListItem>
                                   <asp:ListItem Text="West" Value="1"></asp:ListItem>
                               </asp:RadioButtonList>
                           </EditItemTemplate>
                       </telerik:GridTemplateColumn>
                       <telerik:GridDropDownColumn DataField="TowRegion" HeaderText="Tow Region" ListTextField="Name" ListValueField="Name" UniqueName="TowRegion" ColumnEditorID="TowRegion" Visible="false" DropDownControlType="DropDownList"></telerik:GridDropDownColumn>
                       <telerik:GridDropDownColumn DataField="HaulRectangle" HeaderText="Haul Rectangle" ListTextField="Code" ListValueField="Code" UniqueName="HaulRectangle" ColumnEditorID="HaulRectangle" Visible="false" DropDownControlType="DropDownList"></telerik:GridDropDownColumn
                       <telerik:GridDropDownColumn DataField="WindSpeedCode" HeaderText="Wind Speed" ListTextField="Name" ListValueField="Code" UniqueName="WindSpeed" ColumnEditorID="WindSpeed" Visible="false" DropDownControlType="DropDownList"></telerik:GridDropDownColumn>                   
                       <telerik:GridDropDownColumn DataField="WindDirectionCode" HeaderText="Wind Direction" ListTextField="Name" ListValueField="Code" UniqueName="WindDirection" ColumnEditorID="WindDirection" Visible="false" DropDownControlType="DropDownList"></telerik:GridDropDownColumn>
                       <telerik:GridDropDownColumn DataField="SeaStateCode" HeaderText="Sea State" ListTextField="Name" ListValueField="Code" UniqueName="SeaState" ColumnEditorID="SeaState" Visible="false" DropDownControlType="DropDownList"></telerik:GridDropDownColumn>   
                       <telerik:GridDropDownColumn DataField="SelectivityDeviceCode" HeaderText="Selectivity Device" ListTextField="nvcSelectivityDeviceName" ListValueField="intSelectivityDeviceID" UniqueName="SelectivityDevice" Visible="false" DropDownControlType="DropDownList"></telerik:GridDropDownColumn>                
                    </Columns>
                  </MasterTableView>
              </telerik:RadGrid>

And the table that contains the comboboxes is as follows:

<table class="tbldialog" id="Table1" cellspacing="1" cellpadding="1" width="500" border="0">
            <tr>
                <td><asp:label id="lblId" runat="server" CssClass="label">Observer Name</asp:label></td>
                <td>
                    <asp:DropDownList ID="ddlID" runat="server" DataSourceID="ODS_Observers" DataTextField="ObserverName" DataValueField="ObserverInitials" CssClass="inputLong" AutoPostBack="True"></asp:DropDownList>
                    <asp:ObjectDataSource ID="ODS_Observers" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetData" TypeName="DS_DiscardsTableAdapters.USP_ObserversSelectTableAdapter"></asp:ObjectDataSource>
                  </td>
            </tr>
            <tr>
              <td><asp:Label ID="lblYear" runat="server" CssClass="label">Year:</asp:Label></td>
              <td>
               <asp:DropDownList ID="ddlYear" runat="server" AutoPostBack="True" CssClass="inputLong" DataSourceID="objTripCodeYears" DataTextField="TripYears" DataValueField="TripYears"></asp:DropDownList>
                  <asp:ObjectDataSource ID="objTripCodeYears" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetDataTripCodeYears" TypeName="TripCodeYearsTableAdapters.SelectYearsFromTripCodesByIDTableAdapter">
                     <SelectParameters>
                             <asp:ControlParameter ControlID="ddlID" Name="ObserverID" PropertyName="SelectedValue" Type="String" />
                         </SelectParameters>
                   </asp:ObjectDataSource>               
              </td>
            </tr>
                <tr>
                    <td><asp:label id="lblTripCode" runat="server" CssClass="label">Trip Code:</asp:label></td>
                    <td>
                    <asp:Label ID="lblTripCount" runat="server" CssClass="labelNoCount" Visible="false"></asp:Label>
                      <asp:DropDownList ID="ddlTripCode" runat="server" AutoPostBack="True" CssClass="inputLong" DataSourceID="objTripCodes" DataTextField="TripCode" DataValueField="TripCode"></asp:DropDownList>
                      <asp:ObjectDataSource ID="objTripCodes" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetDisTripCodesByIDAndYear" TypeName="TripCodeYearsTableAdapters.DisGetTripCodesByIDAndYearTableAdapter">
                       <SelectParameters>
                             <asp:ControlParameter ControlID="ddlID" Name="ObserverID" PropertyName="SelectedValue" Type="String" />
                             <asp:ControlParameter ControlID="ddlYear" Name="TripYear" PropertyName="SelectedValue" Type="Int32" />
                         </SelectParameters>
                     </asp:ObjectDataSource>
                   </td>
                </tr>
             </table>

Whenever the ddlTripCode SelectedValue is changed, the grid needs rebound. The problem is that when ddlTripCode SelectedValue changes, the NeedDataSource appears to be retaining the PREVIOUS SelectedValue, not the new one.

Here is my NeedDataSource code:

Protected Sub RDHauls_NeedDataSource(ByVal source As Object, ByVal e As GridNeedDataSourceEventArgs) Handles RDHauls.NeedDataSource
            ' Get the Trip Code for binding the grid
            TripCode = RTrim(CStr(ddlTripCode.SelectedValue))
            ' Get all the haul(s) details for the trip code selected
            Dim ds As New DSHaulsTableAdapters.DisGetHaulDetailsByTripcodeTableAdapter
            ' Bind the grid to the haul(s) details
            RDHauls.DataSource = ds.GetHaulDetailsByTripcode(TripCode)
        End Sub

Any advice please? I have to keep re-selecting a ddlTripCode SelectedValue to get the grid to bind to the correct data.

Thank you, Ida

9 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 Nov 2013, 05:02 AM
Hi Ida,

You have to call the Rebind() method on the OnSelectedIndexChanged of the DropDownList so as to raise the OnNeedDataSource event of the RadGrid.

VB:
Protected Sub ddlTripCode_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles ddlTripCode.SelectedIndexChanged
  RDHauls.Rebind()
End Sub

Thanks,
Shinu
0
Ida
Top achievements
Rank 1
answered on 19 Nov 2013, 11:58 AM
Hi Shinu

I placed RDHauls.Rebind() on all 3 of my dropdowns in my table.

The grid is still rebinding on the PREVIOUS selected trip code.

Ida
0
Shinu
Top achievements
Rank 2
answered on 20 Nov 2013, 06:57 AM
Hi Ida,

The code works fine at my end, here is a sample code that i have tried.

ASPX:
<table class="tbldialog" id="Table1">
    <tr>
        <td>
            <asp:Label ID="lblId" runat="server">OrderID</asp:Label>
        </td>
        <td>
            <asp:DropDownList ID="ddlID" runat="server" DataSourceID="SqlDataSource2" DataTextField="OrderID"
                DataValueField="OrderID" AutoPostBack="True" OnSelectedIndexChanged="ddlID_SelectedIndexChanged">
            </asp:DropDownList>
        </td>
    </tr>
    <tr>
        <td>
            <asp:Label ID="lblCustomerID" runat="server">CustomerID</asp:Label>
        </td>
        <td>
            <asp:DropDownList ID="ddlCustomerID" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2"
                DataTextField="CustomerID" DataValueField="CustomerID" OnSelectedIndexChanged="ddlCustomerID_SelectedIndexChanged">
            </asp:DropDownList>
        </td>
    </tr>
    <tr>
        <td>
            <asp:Label ID="lblShipCity" runat="server">ShipCity</asp:Label>
        </td>
        <td>
            <asp:DropDownList ID="ddlShipCity" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2"
                DataTextField="ShipCity" DataValueField="ShipCity" OnSelectedIndexChanged="ddlShipCity_SelectedIndexChanged">
            </asp:DropDownList>
        </td>
    </tr>
</table>
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="true" GridLines="None"
    AllowPaging="true" AutoGenerateEditColumn="false" OnNeedDataSource="RadGrid1_NeedDataSource">
    <MasterTableView DataKeyNames="OrderID" CommandItemDisplay="Top">
    </MasterTableView>
</telerik:RadGrid>

VB:
Protected Sub RadGrid1_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
       Dim id As String = ddlID.SelectedValue
       Dim custid As String = ddlCustomerID.SelectedValue
       Dim city As String = ddlShipCity.SelectedValue
       RadGrid1.DataSource = "Your Code to populate the Radgrid";
    End Sub
 
Protected Sub ddlID_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles ddlTripCode.SelectedIndexChanged
   RadGrid1.Rebind()
    End Sub
 
Protected Sub ddlCustomerID_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles ddlTripCode.SelectedIndexChanged
   RadGrid1.Rebind()
    End Sub
 
Protected Sub ddlShipCity_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles ddlTripCode.SelectedIndexChanged
  RadGrid1.Rebind()
    End Sub

Thanks,
Shinu
0
Ida
Top achievements
Rank 1
answered on 27 Nov 2013, 02:41 PM
Hi Shinu.

Thanks for your help. When the page first loads, all is fine.

Battled with trying to get the grid to refresh as I wanted, with no luck :-(

The grid seems to refresh correctly ONLY when DropDownList ID="ddlTripCode" is changed.

When either of the 2 dropdowns ddlYear or ddlID are changed, the dropdown ddlTripCode is rebounded and its values change. I want the newly calculated, presented, selected value of ddlTripCode to be used as the parameter to rebind/refresh the grid. The grid is still rebinding on the PREVIOUS trip code that was shown on the screen as the selected value.
0
Shinu
Top achievements
Rank 2
answered on 28 Nov 2013, 01:03 PM
Hi Ida,

I guess you may be using DataTable to bind the data to RadGrid, if you are, then please try clearing the DataTable before filling again with data. if this doesn't help you please provide your code that you use for binding the RadGrid.

VB:
Dim myDataTable As New DataTable()
myDataTable.Clear()

Thanks,
Shinu
0
Ida
Top achievements
Rank 1
answered on 05 Dec 2013, 05:15 PM
Ahhh, maybe getting somewhere then Shinu. Thank you.

I am using a tableadapter to bind data to the grid:

Protected Sub RDHauls_NeedDataSource(ByVal source As Object, ByVal e As GridNeedDataSourceEventArgs) Handles RDHauls.NeedDataSource
    ' Get the Trip Code for binding the grid
    TripCode = RTrim(CStr(ddlTripCode.SelectedValue))
    ' Get all the haul(s) details for the trip code selected
    Dim ds As New DSHaulsTableAdapters.DisGetHaulDetailsByTripcodeTableAdapter
    ' Bind the grid to the haul(s) details
    RDHauls.DataSource = ds.GetHaulDetailsByTripcode(TripCode)
End Sub

Is it possible to clear what I have extracted using the tableadapter please?

Thank you. Ida
0
Shinu
Top achievements
Rank 2
answered on 06 Dec 2013, 05:08 AM
Hi Ida,

Can you try TableAdapter.ClearBeforeFill ,it determines whether a data table is emptied before you call one of the Fill methods.
Please try and let me know.

Thanks,
Shinu
0
Ida
Top achievements
Rank 1
answered on 17 Dec 2013, 04:39 PM
Hi Shinu,

I did try to ensure the tableadapter was cleared before filling again, though still getting the same outcome as before.

Protected Sub RDHauls_NeedDataSource(ByVal source As Object, ByVal e As GridNeedDataSourceEventArgs) Handles RDHauls.NeedDataSource 
           ' Get the Trip Code for binding the grid 
           TripCode = RTrim(CStr(ddlTripCode.SelectedValue)) 
             ' Get all the haul(s) details for the trip code selected 
           Dim ds As New DSHaulsTableAdapters.DisGetHaulDetailsByTripcodeTableAdapter 
           ds.ClearBeforeFill = True 
           ' Bind the grid to the haul(s) details 
           RDHauls.DataSource = ds.GetHaulDetailsByTripcode(TripCode) 
       End Sub

When either of the 2 dropdowns ddlYear or ddlID are changed, the dropdown ddlTripCode is rebounded and its values change. I want the tripcode that is shown at the top of the ddlTripCode dropdownlist to be used as the parameter to bind the radgrid. Instead, what is happening is that when ddlYear or ddlID selections are changed, the grid rebinds on the PREVIOUS trip code that was shown on the screen as the selected value.
0
Kostadin
Telerik team
answered on 20 Dec 2013, 02:31 PM
Hello Ida,

I noticed that ddlTripCode is bound to an ObjectDataSource and ddlYear and ddlID are used to create the data for the ddlTripCode dropdown based on their selection. In case when you choose some item from the ddlYear or ddlID dropdowns the ddlTripCode will rebind and it will display the default value (first item). In this case you the grid will be bound based on that value. I would recommend you to reconsider your logic or use a Session to store the last selected item from the ddlTripCode and bound the grid based on it.

Regards,
Kostadin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Ida
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Ida
Top achievements
Rank 1
Kostadin
Telerik team
Share this question
or