Auto Populate DropDownList on page_load

2 posts, 0 answers
  1. Kevin
    Kevin avatar
    3 posts
    Member since:
    Jan 2019

    Posted 04 Jan 2019 Link to this post

    I have an array of items of possible CSV fields that when the page load i need it to auto populate with the correct field name of the CSV, 

    <div id="divRadGridCsvImport_Wrapper" class="RadGridWrapper">
                        <telerik:RadGrid EnableLinqExpressions="False" ID="radgridCsvMapping" runat="server" AutoGenerateColumns="false" AllowPaging="False" AllowSorting="False" GridLines="None" Width="500">
                            <ClientSettings EnableRowHoverStyle="true"></ClientSettings>


                            <MasterTableView>
                                <Columns>
                                    <telerik:GridTemplateColumn HeaderText="CSV Field">
                                        <ItemTemplate>
                                            <asp:Label ID="CSVfield" runat="server" Text='<%#DataBinder.Eval(Container, "DataItem.CSVfield")%>'></asp:Label>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn HeaderText="Sample Data">
                                        <ItemTemplate>
                                            <asp:Label ID="SampleData" runat="server" Text='<%#DataBinder.Eval(Container, "DataItem.CSVfield")%>'></asp:Label>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn HeaderText="System Field">
                                        <ItemTemplate>
                                            <asp:DropDownList CssClass="inputfields" ID="dropDownColumnName" onchange="FieldMappingsOnChange(this)" runat="server" />
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    
                                
                                </Columns>
                                <NoRecordsTemplate>
                                    <div>
                                        <asp:Literal ID="litNoRecords" runat="server" Text="No Records" />
                                    </div>
                                </NoRecordsTemplate>
                            </MasterTableView>
                        </telerik:RadGrid>
                    </div>

    See in the image loaded, i'm trying to make it easier for users so if a match to the field with our field names is closer i.e. same names or close to as possible, it will load these when the page loads. then the user can change and fill in the ones that couldn't be automatically populated. I think Load On Demand may work, but before i try this, i'd like to know if it can be done or what others are doing.

     

    Thanks

  2. Vessy
    Admin
    Vessy avatar
    2367 posts

    Posted 09 Jan 2019 Link to this post

    Hi Kevin,

    You can set the SelectedValue  use RadDropDownlist depending on the current row data in a similar way :
    <telerik:RadDropDownList RenderMode="Lightweight" runat="server" ID="RadDropDownList1"  DataTextField="CategoryName"
        DataValueField="CategoryID" DataSourceID="CategoriesDataSource" SelectedValue='<%#Bind("CategoryID") %>'>
    </telerik:RadDropDownList>

    Such approach is demonstrated in the following demo (in the edit template of the Category column:
    https://demos.telerik.com/aspnet-ajax/dropdownlist/examples/applicationscenarios/dropdownlistingird/defaultcs.aspx

    Regards,
    Vessy
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top