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

Assigning a Combobox to a Custom Attribute

2 Answers 86 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Josh
Top achievements
Rank 1
Josh asked on 28 Jun 2010, 04:38 PM
Hello,

Using Q3 2009 & IE7, I have the following scheduler code (advanced template code taken from here):

<telerik:RadScheduler ID="RadScheduler1" runat="server" OnAppointmentDelete="RadScheduler1_AppointmentDelete" 
                OnAppointmentInsert="RadScheduler1_AppointmentInsert" OnAppointmentUpdate="RadScheduler1_AppointmentUpdate" 
                Skin="WebBlue" OnDataBinding="RadScheduler1_DataBinding" SelectedView="WeekView" 
                StartEditingInAdvancedForm="true" StartInsertingInAdvancedForm="true" ShowAllDayRow="false" 
                OnAppointmentDataBound="RadScheduler1_AppointmentDataBound" 
                CustomAttributeNames="avail_type" EnableCustomAttributeEditing="true"
                <AdvancedForm Modal="true" /> 
                <TimelineView UserSelectable="false" /> 
                <AdvancedInsertTemplate> 
                    <div class="rsAdvancedEdit" style="position: relative"
                        <%-- Title bar.--%> 
                        <div class="rsAdvTitle"
                            <%-- The rsAdvInnerTitle element is used as a drag handle when the form is modal. --%> 
                            <h1 class="rsAdvInnerTitle"
                                <asp:Label runat="server" ID="titleBarLabel"
               <%# Container.Appointment.Owner.Localization.GetString("AdvancedInsertTitleBar_Callback")%> 
                                </asp:Label></h1
                            <asp:LinkButton runat="server" ID="AdvancedEditCloseButton" CssClass="rsAdvEditClose" 
                                CommandName="Cancel" CausesValidation="false" ToolTip='<%# Container.Appointment.Owner.Localization.AdvancedClose %>'
       <%# Container.Appointment.Owner.Localization.AdvancedClose%> 
                            </asp:LinkButton> 
                        </div> 
                        <div class="rsAdvContentWrapper"
                         
                        <table> 
                        <tr><td
                        <asp:Label runat="server" ID="AvailabilityLabel"
                        <%# Container.Appointment.Owner.Localization.GetString("AvailabilityLabel_Callback")%> 
                        </asp:Label> 
                        </td> 
                        <td> 
                         
                        <telerik:RadComboBox runat="server" ID="AvailComboBox" OnDataBinding="AvailComboBox_DataBinding" Skin="WebBlue" DataValueField="avail_type" DataTextField="avail_name" HighlightTemplatedItems="True" EmptyMessage='<%# Container.Appointment.Owner.Localization.Save %>'
                        <ItemTemplate> 
                        <asp:Image runat="server" ID="AvailabilityDDImage" ImageUrl='<%# "~/images/colors/" + Eval("color").ToString().Trim() + ".gif" %>' ToolTip='<%# "~/images/colors/" + Eval("color").ToString().Trim() + ".gif" %>' /> 
                        <asp:Label runat="server" ID="AvailabilityDDLabel" Text='<%# Eval("avail_name") %>'></asp:Label> 
                        <asp:HiddenField runat="server" ID="hidAvailType" Value='<%# Bind("avail_type") %>' /> 
                        </ItemTemplate> 
                        </telerik:RadComboBox> 
                        </td> 
                      
                        </tr> 
                        </table> 
              
                            Custom content here... 
                            <asp:Panel runat="server" ID="ButtonsPanel" CssClass="rsAdvancedSubmitArea"
                                <div class="rsAdvButtonWrapper"
                   <asp:LinkButton CommandName="Insert" runat="server" ID="InsertButton" CssClass="rsAdvEditSave"
<span><%# Container.Appointment.Owner.Localization.Save%></span
                   </asp:LinkButton> 
                   <asp:LinkButton runat="server" ID="CancelButton" CssClass="rsAdvEditCancel" CommandName="Cancel" 
                       CausesValidation="false"
<span><%# Container.Appointment.Owner.Localization.Cancel%></span
                   </asp:LinkButton> 
               </div> 
                            </asp:Panel> 
                        </div> 
                    </div> 
                </AdvancedInsertTemplate> 
            </telerik:RadScheduler> 

Here is the codebehind:
protected void RadScheduler1_AppointmentInsert(object sender, SchedulerCancelEventArgs e) 
        { 
            string test = e.Appointment.Attributes["avail_type"]; 
        } 
 
        protected void RadScheduler1_AppointmentUpdate(object sender, AppointmentUpdateEventArgs e) 
        { 
        } 
 
        protected void RadScheduler1_AppointmentDelete(object sender, SchedulerCancelEventArgs e) 
        { 
        } 
 
protected void AvailComboBox_DataBinding(object sender, EventArgs e) 
        { 
            (sender as RadComboBox).Items.Clear(); 
            DataTable table = new DataTable(); 
            table.Columns.Add("color"); 
            table.Columns.Add("avail_name"); 
            table.Columns.Add("avail_type"); 
 
            DataRow row = table.NewRow(); 
            row["color"] = "Green"
            row["avail_name"] = "Available"
            row["avail_type"] = "AVAIL"
            table.Rows.Add(row); 
 
            row = table.NewRow(); 
            row["color"] = "Red"
            row["avail_name"] = "Not Available"
            row["avail_type"] = "NOTAVAIL"
            table.Rows.Add(row); 
 
            DataView AvailabilityView = table.DefaultView; 
 
            (sender as RadComboBox).DataSource = AvailabilityView; 
            (sender as RadComboBox).SelectedIndex = 0; 
        } 

In particular, I am having great trouble with the combobox (on appointment insert); I simply cannot get the value of it. The string 'test' always returns null. If I try using DataValueField='<%# Bind("avail_type") %>' in the combobox, the string becomes empty instead. I simply wish to get the selected value of the combobox as a custom appointment attribute so that it may be stored in the database. Any help will be appreciated.

Thank you

2 Answers, 1 is accepted

Sort by
0
Accepted
T. Tsonev
Telerik team
answered on 02 Jul 2010, 08:48 AM
Hi Josh,

Apologies for the delayed response and thank you for sharing the code that you're working on.

Everything looks right with one exception - you must bind the SelectedValue to the custom attribute:

<telerik:RadComboBox runat="server" ID="AvailComboBox"
SelectedValue='<%# Bind("avail_type") %>'
OnDataBinding="AvailComboBox_DataBinding" Skin="WebBlue" DataValueField="avail_type" DataTextField="avail_name" HighlightTemplatedItems="True" EmptyMessage='<%# Container.Appointment.Owner.Localization.Save %>'>
                        <ItemTemplate>
                        <asp:Image runat="server" ID="AvailabilityDDImage" ImageUrl='<%# "~/images/colors/" + Eval("color").ToString().Trim() + ".gif" %>' ToolTip='<%# "~/images/colors/" + Eval("color").ToString().Trim() + ".gif" %>' />
                        <asp:Label runat="server" ID="AvailabilityDDLabel" Text='<%# Eval("avail_name") %>'></asp:Label>
                        <asp:HiddenField runat="server" ID="hidAvailType" Value='<%# Bind("avail_type") %>' />
                        </ItemTemplate>
                        </telerik:RadComboBox>

I hope this helps.

Regards,
Tsvetomir Tsonev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Josh
Top achievements
Rank 1
answered on 02 Jul 2010, 04:36 PM
Thanks Tsvetomir, that did the trick. I never thought to use SelectedValue because it never showed up in IntelliSense. Works like a charm now.

Josh
Tags
Scheduler
Asked by
Josh
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
Josh
Top achievements
Rank 1
Share this question
or