Issue binding autocompletebox in edit template of radgrid

3 posts, 0 answers
  1. Erin Manuel
    Erin  Manuel avatar
    3 posts
    Member since:
    Jan 2010

    Posted 15 Jan 2013 Link to this post

     I can't figure out how to bind the selected value of an autocompletebox in a radgrid edittemplate.  I suspect it needs to be added to the autoboxes entries collection, possibly server-side, but can't find examples.  Would be great if it was as easy as SelectedValue='<%# Bind("xSemester_ID") %>'


    Thanks 



            <telerik:RadGrid ID="rgGuestLecture" runat="server" AutoGenerateColumns="False" CellSpacing="0" DataSourceID="ldsGuestLecture" GridLines="None" ondeletecommand="rgGuestLecture_DeleteCommand" oninsertcommand="rgGuestLecture_InsertCommand" onitemcreated="rgGuestLecture_ItemCreated" onupdatecommand="rgGuestLecture_UpdateCommand">
                    <MasterTableView DataSourceID="ldsGuestLecture" CommandItemDisplay="Bottom" DataKeyNames="ID">
                    <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
                    <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
                    <HeaderStyle Width="20px"></HeaderStyle>
                    </RowIndicatorColumn>
                    <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
                    <HeaderStyle Width="20px"></HeaderStyle>
                    </ExpandCollapseColumn>
                        <Columns>
                            <telerik:GridEditCommandColumn UniqueName="GridEditCommandColumn"></telerik:GridEditCommandColumn>
                            <telerik:GridBoundColumn DataField="ID" DataType="System.Int32" FilterControlAltText="Filter ID column" HeaderText="ID" ReadOnly="True" SortExpression="ID" UniqueName="ID" Visible="false"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="FacultyYear_ID" DataType="System.Int32" FilterControlAltText="Filter FacultyYear_ID column" HeaderText="FacultyYear_ID" ReadOnly="True" SortExpression="FacultyYear_ID" UniqueName="FacultyYear_ID" Visible="false"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="xlsRDS_Course_ID" FilterControlAltText="Filter xlsRDS_Course_ID column" HeaderText="xlsRDS_Course_ID" ReadOnly="True" SortExpression="xlsRDS_Course_ID" UniqueName="xlsRDS_Course_ID" DataType="System.Int32" Visible="false"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="xSemester_ID" FilterControlAltText="Filter xSemester_ID column" HeaderText="xSemester_ID" ReadOnly="True" SortExpression="xSemester_ID" UniqueName="xSemester_ID" DataType="System.Int32" Visible="false"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Course_Other" FilterControlAltText="Filter Course_Other column" HeaderText="Course_Other" ReadOnly="True" SortExpression="Course_Other" UniqueName="Course_Other" Visible="false"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="ACAD_CAREER" FilterControlAltText="Filter ACAD_CAREER column" HeaderText="ACAD_CAREER" ReadOnly="True" SortExpression="ACAD_CAREER" UniqueName="ACAD_CAREER" Visible="false"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="SUBJECT_CD" FilterControlAltText="Filter SUBJECT_CD column" HeaderText="SUBJECT_CD" ReadOnly="True" SortExpression="SUBJECT_CD" UniqueName="SUBJECT_CD" Visible="false"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="CATALOG_NBR" FilterControlAltText="Filter CATALOG_NBR column" HeaderText="CATALOG_NBR" ReadOnly="True" SortExpression="CATALOG_NBR" UniqueName="CATALOG_NBR" Visible="false"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="DESCR" FilterControlAltText="Filter DESCR column" HeaderText="DESCR" ReadOnly="True" SortExpression="DESCR" UniqueName="DESCR" Visible="false"></telerik:GridBoundColumn>                
                            <telerik:GridBoundColumn DataField="CourseCode" FilterControlAltText="Filter CourseCode column" HeaderText="Course Code" ReadOnly="True" SortExpression="CourseCode" UniqueName="CourseCode"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Semester" FilterControlAltText="Filter Semester column" HeaderText="Semester" ReadOnly="True" SortExpression="Semester" UniqueName="Semester"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Hours_Count" DataType="System.Decimal" FilterControlAltText="Filter Hours_Count column" HeaderText="Hours Count" ReadOnly="True" SortExpression="Hours_Count" UniqueName="Hours_Count"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Notes" FilterControlAltText="Filter Notes column" HeaderText="Notes" ReadOnly="True" SortExpression="Notes" UniqueName="Notes" Visible="false"></telerik:GridBoundColumn>
                            <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn" ConfirmText="Are you sure you want to delete this record?"></telerik:GridButtonColumn>
                        </Columns>
                        <EditFormSettings EditFormType="Template">
                            <EditColumn UniqueName="eccGuestLecture"></EditColumn>
                            <FormTemplate>
                                <table width="100%" border="0" cellspacing="2" cellpadding="2">
                                    <tr>
                                        <td width="25%">Course: </td>
                                        <td width="75%"><telerik:RadAutoCompleteBox ID="racbCourse" runat="server" DataSourceID="ldsRDSCourses" DataTextField="CourseCode" DataValueField="ID" InputType="Text">
                                            <TextSettings SelectionMode="Single"  />
                                            </telerik:RadAutoCompleteBox></td>
                                    </tr>
                                    <tr>
                                        <td width="25%"><asp:RequiredFieldValidator ID="RequiredFieldValidator22" runat="server" ErrorMessage="*" ForeColor="Red" ControlToValidate="ddlSemester" Display="Dynamic">*</asp:RequiredFieldValidator>Semester: <asp:RequiredFieldValidator ID="RequiredFieldValidator31" runat="server" ErrorMessage="*" ForeColor="Red" ControlToValidate="ddlSemester" Display="Dynamic">*</asp:RequiredFieldValidator></td>
                                        <td width="75%"><asp:DropDownList ID="ddlSemester" Width="50%" runat="server" DataSourceID="ldsSemester" DataTextField="Semester" DataValueField="ID" SelectedValue='<%# Bind("xSemester_ID") %>' AppendDataBoundItems="True"><asp:ListItem Selected="True" Text="Select" Value=""></asp:ListItem></asp:DropDownList></td>
                                    </tr>
                                    <tr>
                                        <td width="25%"><asp:RequiredFieldValidator ID="RequiredFieldValidator32" runat="server" ErrorMessage="*" ForeColor="Red" ControlToValidate="tbHoursCount" Display="Dynamic">*</asp:RequiredFieldValidator>Hours Count: <asp:RequiredFieldValidator ID="RequiredFieldValidator33" runat="server" ErrorMessage="*" ForeColor="Red" ControlToValidate="tbHoursCount" Display="Dynamic">*</asp:RequiredFieldValidator></td>
                                        <td width="75%"><telerik:RadNumericTextBox ID="tbHoursCount" runat="server" Text='<%# Bind("Hours_Count") %>' Skin="Vista" DataType="System.Int32"></telerik:RadNumericTextBox></td>
                                    </tr>
                                </table>
                                <table style="width: 100%">
                                    <tr><td align="left"><asp:Button ID="btnRptdEvnt" runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>' Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'></asp:Button> <asp:Button ID="btnEvntPrsnsCncl" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel"></asp:Button></td></tr>
                                </table>
                            </FormTemplate>
                            </EditFormSettings>
                    </MasterTableView>
                    <FilterMenu EnableImageSprites="False"></FilterMenu>
                </telerik:RadGrid>
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 15 Jan 2013 Link to this post

    Hi,

    In order to set an initially selected Entry in RadAutoCompleteBox you need to add a new entry to control Entries collection.
    You can make this at RadGrid.OnItemDataBound event:

    ASPX:
    <EditFormSettings EditFormType="Template">
           <EditColumn UniqueName="eccGuestLecture">
           </EditColumn>
           <FormTemplate>
              <telerik:RadAutoCompleteBox ID="racbCourse" runat="server" DataSourceID="ldsRDSCourses" DataTextField="CourseCode" DataValueField="ID" InputType="Text">
                  <TextSettings SelectionMode="Single"  />
              </telerik:RadAutoCompleteBox>
            </FormTemplate>
    </EditFormSettings>

    C#:
    protected void rgGuestLecture_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            if (e.Item.IsInEditMode)
            {
                GridEditableItem item = (GridEditableItem)e.Item;
                if (!(e.Item is IGridInsertItem))
                {
                    RadAutoCompleteBox auto = (RadAutoCompleteBox)item.FindControl("racbCourse");
                    auto.Entries.Add(new AutoCompleteBoxEntry(item["CourseCode"].Text, item["ID"].Text));
                }
            }
        }

    Hope this helps.

    Regards,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Erin Manuel
    Erin  Manuel avatar
    3 posts
    Member since:
    Jan 2010

    Posted 16 Jan 2013 Link to this post

    Thank you very much.  That is just what I was looking for!
Back to Top