or
var lstEmployees = employeeRepository.All.Select(employee => new { employee.Id, employee.Name });
txtEmployee.DataSource = lstEmployees.ToList();
txtEmployee.DataTextField = "Name";
txtEmployee.DataValueField = "Id";
txtEmployee.DataBind();
This code is called in the Page_Load() event inside the
if (!IsPostBack) block.
This triggers the error "The Control DataSource or (DataSourceID) is not set" when I start typing into it.
What I noticed is, when I move the binding code outside the if (!IsPostBack) block, it works correctly.

protected void RadGrid1_ExcelMLExportStylesCreated(object source, GridExportExcelMLStyleCreatedArgs e) { StyleElement dateStyle = new StyleElement("Date"); dateStyle.NumberFormat.FormatType = NumberFormatType.Fixed; dateStyle.NumberFormat.Attributes["ss:Format"] = "d"; e.Styles.Add(dateStyle); } }<telerik:RadGrid SkinID="myTemplate" ID="myGrid" runat="server" DataSourceID="myDataSourceID" OnInsertCommand="OnInserting" OnUpdateCommand="OnUpdating"> <MasterTableView DataKeyNames="myDataKey"> <CommandItemSettings AddNewRecordText="Assign Location" /> <EditFormSettings CaptionFormatString="Edit Location" InsertCaption="Add New Location" EditFormType="Template"> <FormTemplate> <!-- Begin Edit Item Table Template --> <table id="Table10"> <tr> <td> <des:LocalizableLabel ID="Location" runat="server" Text="Location"></des:LocalizableLabel> </td> <td> <aec:TelerikAutoCompleteBox ID="locationsAutoComplete" runat="server" DataSourceID="sqlLocationAutocomplete" DataTextField="Name" DataValueField="Location_ID" Filter="Contains" TextSettings-SelectionMode="Single" InputType="Text"> </aec:TelerikAutoCompleteBox> </td> </tr> <tr> <td> <des:LocalizableLabel ID="StorageLocation" runat="server" Text="Storage Location"></des:LocalizableLabel> </td> <td> <aec:TelerikDropDown runat="server" DataField="Storage_Location" DataTextField="Storage_Location" DataValueField="Storage_Location" DataSourceID="sqlStorageLocation" ID="storageLocationDropDown"> </aec:TelerikDropDown> <asp:CustomValidator runat="server" ID="customValidator1" ClientValidationFunction="EquipmentLocation_ClientValidate" OnServerValidate="validateLocation" ControlToValidate="storageLocationDropDown" ErrorMessage="Must select either Location or Storage Location." Display="static"> </asp:CustomValidator> </td> </tr> </table> <AERadGrid:EditFormSaveCancelButtons ID="locationAssignEditFormButtons" runat="Server"> </AERadGrid:EditFormSaveCancelButtons> <!-- End Edit Item Table Template --> </FormTemplate> </EditFormSettings> <Columns> <telerik:GridBoundColumn UniqueName="Location_Name" HeaderText="Location" DataField="Location_Name"> </telerik:GridBoundColumn> <telerik:GridBoundColumn UniqueName="Storage_Location" HeaderText="Storage Location" DataField="Storage_Location"> </telerik:GridBoundColumn> </Columns> </MasterTableView></telerik:RadGrid>function EquipmentLocation_ClientValidate(source, args) { //get a reference to the calling validator control var CustomValidator1 = source.id; /* get the values of the location auto complete and the storage location ddl and compare.*/ var storageLocation = args.Value; var location = ?? //GET the value out of the autocomplete box....how? }When adding a LinkButton to a GridDataItem in an ajaxified RadGrid, it causes a full postback. I do not want a full postback.
This is my code:
private void GridItem_ItemCreated(object sender, GridItemEventArgs e) { if (e.Item is GridDataItem) { GridDataItem item = (e.Item as GridDataItem); //cannot .Clear() expand/collapse item item["ExpandColumn"].Controls[0].Visible = false; LinkButton expand = CreateLinkButton(); expand.CommandArgument = _expandText; expand.ID = _btnExpand; item["ExpandColumn"].Controls.Add(expand); LinkButton collapse = CreateLinkButton(); collapse.CommandArgument = _collapseText; collapse.ID = _btnCollapse; item["ExpandColumn"].Controls.Add(collapse); //hide collapse on load item["ExpandColumn"].Controls[2].Visible = false; foreach (Control control in item["ExpandColumn"].Controls) { RadAjaxManager RadAjaxManager1 = RadAjaxManager.GetCurrent((System.Web.UI.Page)System.Web.HttpContext.Current.Handler); RadAjaxManager1.AjaxSettings.AddAjaxSetting(control, (sender as RadGrid)); } }}
I've even tried the below on RadGrid_PreRender with no luck
private void RadGrid_PreRender(object sender, EventArgs e)
{
RadAjaxManager RadAjaxManager1 = RadAjaxManager.GetCurrent((System.Web.UI.Page)System.Web.HttpContext.Current.Handler);
RadAjaxManager1.AjaxSettings.AddAjaxSetting((Control)sender, (Control)sender);
RadAjaxManager1.EnableAJAX = true;
}
<telerik:RadGrid ID="grdBusinessRoles" runat="server" AllowMultiRowSelection="false" AllowFilteringByColumn="true" ShowFooter="false" AllowSorting="True" AutoGenerateColumns="False" AllowPaging="true"> <MasterTableView AutoGenerateColumns="false" EditMode="InPlace" TableLayout="Auto" CommandItemDisplay="Top" DataKeyNames="BusinessRoleId2,BusinessRoleId" PageSize="15"> <CommandItemTemplate> <asp:LinkButton runat="server" ID="btnClear" Text="Clear Filters" CommandName="ClearFilters" /> </CommandItemTemplate> <Columns> <telerik:GridBoundColumn UniqueName="colStream" DataField="StreamName" HeaderText="Stream" SortExpression="StreamName" ReadOnly="true"> <FilterTemplate> <telerik:RadComboBox ID="rcbStreams" DataTextField="Value" DataValueField="Value" AppendDataBoundItems="true" AutoPostBack="false" SelectedValue='<%# TryCast(Container, GridItem).OwnerTableView.GetColumn("colStream").CurrentFilterValue %>' runat="server" OnClientSelectedIndexChanged="SelectedIndexChanged"> <Items> <telerik:RadComboBoxItem /> </Items> </telerik:RadComboBox> <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server"> <script type="text/javascript"> function SelectedIndexChanged(sender, args) { var tableView = $find("<%# TryCast(Container, GridItem).OwnerTableView.ClientID %>"); tableView.filter("colStream", args.get_item().get_value(), "EqualTo"); } </script> </telerik:RadScriptBlock> </FilterTemplate> </telerik:GridBoundColumn> </Columns> <NoRecordsTemplate> <asp:Label runat="server" ID="lblNoRecords" Text="No Business Roles found."></asp:Label> </NoRecordsTemplate> <PagerStyle PageSizeControlType="RadComboBox" /> </MasterTableView> <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle> <FilterMenu EnableImageSprites="False"> </FilterMenu> <ClientSettings EnableRowHoverStyle="true"> <Selecting AllowRowSelect="true" /> </ClientSettings></telerik:RadGrid><!-- Select Business Roles --><telerik:RadWindow runat="server" ID="wdwBusinessRoles" Modal="true" Width="820px" Height="500px" Behaviors="Close" CssClass="RadWindow_Pram"> <ContentTemplate> <telerik:RadAjaxPanel ID="pnlBusinessRoles" runat="server"> <pram:ucBusinessRoles ID="ucSelectBusinessRole" runat="server" TypeOfList="AssignRoleVariants" TypeOfSelection="SingleSelection" AllowNavigation="False" AllowNewBusinessRole="False" /> </telerik:RadAjaxPanel> <telerik:RadButton ID="btnAddRolesToList" runat="server" Text="Select Role" CssClass="RadButton_Pram submit" /> </ContentTemplate></telerik:RadWindow>Protected Sub grdBusinessRoles_ItemCreated(ByVal sender As Object, ByVal e As GridItemEventArgs) _ Handles grdBusinessRoles.ItemCreated If TypeOf (e.Item) Is GridFilteringItem Then Dim filterItem As GridFilteringItem = CType(e.Item, GridFilteringItem) Dim combo As RadComboBox = CType(filterItem("colStream").FindControl("RadComboBoxClientName"), RadComboBox) combo.DataSource = Streams ' This is a Dictionary(Of Decimal, String) combo.DataValueField = "value" combo.DataTextField = "value" End IfEnd Sub<telerik:RadNumericTextBox runat="server" ID="_tbTickerSpeed" ShowSpinButtons="True" Label="Ticker Speed" > <NumberFormat DecimalDigits='0' /> <EnabledStyle HorizontalAlign='Right' /></telerik:RadNumericTextBox><div id="ctl00_Main__playerLocalSettingsControl__tbTickerSpeed_wrapper" class="RadInput RadInput_Default" style="width: 125px; display: inline-block; "> <table cellpadding="0" cellspacing="0" class="riTable" style="border-width:0;border-collapse:collapse;width:100%;"> <tbody><tr> <td><label class="riLabel" for="ctl00_Main__playerLocalSettingsControl__tbTickerSpeed_text" id="ctl00_Main__playerLocalSettingsControl__tbTickerSpeed_Label">Ticker Speed</label></td><td class="riCell" style="width:100%;white-space:normal;"><input type="text" id="ctl00_Main__playerLocalSettingsControl__tbTickerSpeed_text" name="ctl00_Main__playerLocalSettingsControl__tbTickerSpeed_text" class="riTextBox riEnabled" style="width: 100%; text-align: right; " maxlength="524288"><input style="visibility:hidden;float:right;margin:-18px 0 0 -1px;width:1px;height:1px;overflow:hidden;border:0;padding:0;" id="ctl00_Main__playerLocalSettingsControl__tbTickerSpeed" class="rdfd_" value="" type="text" title=""><input style="visibility:hidden;float:right;margin:-18px 0 0 -1px;width:1px;height:1px;overflow:hidden;border:0;padding:0;" id="ctl00_Main__playerLocalSettingsControl__tbTickerSpeed_Value" class="rdfd_" name="ctl00$Main$_playerLocalSettingsControl$_tbTickerSpeed" value="" type="text" title=""></td><td class="riSpin"><a class="riUp" href="javascript:void(0)" id="ctl00_Main__playerLocalSettingsControl__tbTickerSpeed_SpinUpButton"><span>Spin Up</span></a><a class="riDown" href="javascript:void(0)" id="ctl00_Main__playerLocalSettingsControl__tbTickerSpeed_SpinDownButton"><span>Spin Down</span></a></td> </tr> </tbody></table><input id="ctl00_Main__playerLocalSettingsControl__tbTickerSpeed_ClientState" name="ctl00_Main__playerLocalSettingsControl__tbTickerSpeed_ClientState" type="hidden" autocomplete="off"> </div><span id="ctl00_Main__playerLocalSettingsControl__tbTickerSpeed_wrapper" class="riSingle riContSpinButtons RadInput RadInput_Windows7" style="width:160px;"> <label class="riLabel" for="ctl00_Main__playerLocalSettingsControl__tbTickerSpeed" id="ctl00_Main__playerLocalSettingsControl__tbTickerSpeed_Label" style="width:64px;">Ticker Speed </label> <span class="riContentWrapper" style="width:96px;"> <span class="riDisplay" id="ctl00_Main__playerLocalSettingsControl__tbTickerSpeed_display" style="color: rgb(0, 0, 0); display: inline; font-family: 'segoe ui', arial, sans-serif; font-size: 12px; line-height: normal; text-align: right; padding-left: 5px; padding-right: 5px; border-left-width: 1px; border-right-width: 20px; "> 10 </span> <input id="ctl00_Main__playerLocalSettingsControl__tbTickerSpeed" name="ctl00$Main$_playerLocalSettingsControl$_tbTickerSpeed" type="text" class="riTextBox riEnabled" style="text-align: right; color: transparent; "><a class="riUp" href="javascript:void(0)" id="ctl00_Main__playerLocalSettingsControl__tbTickerSpeed_SpinUpButton"><span>Spin Up</span></a><a class="riDown" href="javascript:void(0)" id="ctl00_Main__playerLocalSettingsControl__tbTickerSpeed_SpinDownButton"><span>Spin Down</span></a></span> <input id="ctl00_Main__playerLocalSettingsControl__tbTickerSpeed_ClientState" name="ctl00_Main__playerLocalSettingsControl__tbTickerSpeed_ClientState" type="hidden" autocomplete="off" value="{"enabled":true,"emptyMessage":"","minValue":-70368744177664,"maxValue":70368744177664}"></span>