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

Template Column help, please....

1 Answer 85 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Abby
Top achievements
Rank 1
Abby asked on 19 Feb 2015, 07:40 PM
I have created a radgrid that functions with edit inplace and updates from an outside button to update an receords that were changed.  
I also would like to use the insert button to be able to add a new record. 
I am running in to a problem with the dropdowns because on an insert there is not a value to 'bind/eval', I need the dropdown to say "select' or something similar.  
Can I combine both items in the way I am trying?  I've attached the aspx from my column.  
Please advise.

                <telerik:GridTemplateColumn  UniqueName="PartNumber" SortExpression="PartNumber" AllowFiltering ="true"
                        HeaderText="Part Number"  ReadOnly="false" ItemStyle-VerticalAlign="Top" Visible="true" >
                             <ItemTemplate>
                           <asp:DropDownList ID="DropPart" runat="server" DataSourceID="dsPartNumbers" DataTextField="PartNumber" 
                                DataValueField="CustomerPartNumberID" SelectedValue='<%# DataBinder.Eval(Container.DataItem,"CustomerPartNumberID") %>'  >
                            </asp:DropDownList>
                            </ItemTemplate>
                              <EditItemTemplate>
                                 <asp:DropDownList ID="EditDropPartNumber" runat="server" DataSourceID="dspartNumbers" DataTextField="PartNumber" AppendDataBoundItems="true"
                                DataValueField="CustomerPartNumberID" SelectedValue='<%# bind("CustomerPartNumberID") %>'>
                                  </asp:DropDownList>
                                  <asp:RequiredFieldValidator ID="Validator1" ControlToValidate="EditDropPartNumber" 
                                  ErrorMessage="*Required" runat="server" Display="Dynamic" InitialValue="-- Select --" ForeColor="Red">
                                      </asp:RequiredFieldValidator>
                                </EditItemTemplate>
                    </telerik:GridTemplateColumn>

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 24 Feb 2015, 02:11 PM
Hello Abby,

For achieving the desired result, you will have to set the AppendDataBoundItems property of the DropDownList control to true and include an item in the Items collection that will handle the null value coming from the inserted item:
<asp:DropDownList ID="ddlTOC" runat="server" SelectedValue='<%# Bind("TitleOfCourtesy") %>' ..................
    AppendDataBoundItems="True">
    <asp:ListItem Selected="True" Text="Select" Value="">
    </asp:ListItem>
</asp:DropDownList>

Hope this helps.


Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Abby
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or