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

Populate Drop-Down List in Edit Mode Form Template

2 Answers 798 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 12 Feb 2015, 05:04 PM
I have a custom Edit mode Form Template defined with a Drop-Down List and 3 check boxes. I want to pre-load the Drop-down list from a related table. 
That way when I click edit on a grid row, the custom form pops up and the correct text will be selected in the drop-down based on the lookup value in the source
table and I will be able to change the drop down if I like. When I reference the drop down list ID name in the code behind it doesn't recognize it. The name of the drop down list is ddlWebPages. How can I accomplish this?

Here is my markup code for the Grid:
<telerik:RadGrid ID="RadGridwebpagemanagement" CssClass="webpageManagementGrid" MasterTableView-DataKeyNames="ID" runat="server"
            AllowFilteringByColumn="True" AllowSorting="True"
            GroupPanelPosition="Top"  
            OnNeedDataSource="RadGridwebpagemanagement_NeedDataSource"
            OnUpdateCommand="RadGridwebpagemanagement_UpdateCommand">
            <ClientSettings>
                <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                <Selecting AllowRowSelect="true" />
            </ClientSettings>
            <MasterTableView AutoGenerateColumns="false" CommandItemDisplay="Top" CommandItemSettings-AddNewRecordText="Add New Webpage" 
                 InsertItemPageIndexAction="ShowItemOnCurrentPage">
 
                <columns>
                     
 
                    <telerik:GridBoundColumn DataField="webpage_name" HeaderText="Web Page" UniqueName="webpage_name" ItemStyle-Font-Names="Arial" ItemStyle-Font-Bold="true"
                                FilterControlWidth="150px">
                                <HeaderStyle Width="200px" Font-Names="Arial" />
                                <ItemStyle Width="200px" />
                    </telerik:GridBoundColumn>
 
                    <telerik:GridCheckBoxColumn DataField="add_privledge" HeaderText="Allow Adds" UniqueName="add_privledge"
                                FilterControlWidth="120px">               
                                <HeaderStyle Width="120px" Font-Names="Arial" />
                                <ItemStyle Width="120px" />
                    </telerik:GridCheckBoxColumn>
                     
                    <telerik:GridCheckBoxColumn DataField="edit_privledge" HeaderText="Allow Edits" UniqueName="edit_privledge"
                                FilterControlWidth="120px">               
                                <HeaderStyle Width="120px" Font-Names="Arial" />
                                <ItemStyle Width="120px" />
                   </telerik:GridCheckBoxColumn>
 
                     <telerik:GridCheckBoxColumn DataField="delete_privledge" HeaderText="Allow Deletes" UniqueName="delete_privledge"
                              FilterControlWidth="120px">               
                                <HeaderStyle Width="120px" Font-Names="Arial" />
                                <ItemStyle Width="120px" />
                    </telerik:GridCheckBoxColumn>                  
 
                   <telerik:GridEditCommandColumn ButtonType="LinkButton" EditText="Edit" CancelText="Cancel" ItemStyle-Width="50px" HeaderStyle-Width="50px" FilterControlWidth="50px" />
                   <telerik:GridButtonColumn ConfirmText="Delete this product?" ConfirmDialogType="RadWindow"
                        ConfirmTitle="Delete" ButtonType="LinkButton" Text="Delete" CommandName="Delete" ItemStyle-Width="50px" HeaderStyle-Width="50px" FilterControlWidth="50px" />
                     
                </columns>
                <EditFormSettings EditFormType="Template">
                     
                    <FormTemplate>
                        <div id="divGridEdit" class="divGrid">
                            <b>Add New Role to Webpage Association</b>
                            <br /><br />
                            <table>
 
                                <tr>
                                    <td><asp:Label Text="Web Page:" runat="server"></asp:Label></td>
                                    <td><asp:DropDownList ID="ddlWebPages" runat="server"></asp:DropDownList></td>
                                </tr>
                                <tr>
                                     <td><asp:Label Text="Allow Add:" runat="server"></asp:Label></td>
                                     <td><asp:CheckBox ID="chkboxAllowAdd" Checked='<%# Bind("add_privledge") %>' runat="server" /></td>
                                </tr>
                                <tr>
                                     <td><asp:Label Text="Allow Edit:" runat="server"></asp:Label></td>
                                     <td><asp:CheckBox ID="chkboxAllowEdit" Checked='<%# Bind("add_privledge") %>' runat="server" /></td>
                                </tr>
                                <tr>
                                     <td><asp:Label Text="Allow Delete:" runat="server"></asp:Label></td>
                                     <td><asp:CheckBox ID="chkboxDelete" Checked='<%# Bind("add_privledge") %>' runat="server" /></td>
                                </tr>
                                <tr>
                                    <td><br /></td>
                                    <td></td>
                                </tr>
                                <tr>
                                    <td><asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                        CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'  runat="server" /></td>
                                    <td><asp:Button ID="btnCancel" Text="Cancel" runat="server" CommandName="Cancel" CausesValidation="false" /></td>
                                </tr>
                            </table>
                        </div>                     
                    </FormTemplate>
 
                </EditFormSettings>
                
            </MasterTableView>
            <ClientSettings>
                <ClientEvents OnRowDblClick="rowDblClick" />
            </ClientSettings>
                
        </telerik:RadGrid>


2 Answers, 1 is accepted

Sort by
0
Accepted
davortsan
Top achievements
Rank 1
answered on 12 Feb 2015, 08:36 PM
Hi David,

I had a similiar issue tan your. I had a custom Edit Form Template with a DropDownList inside. I needed to show a specific value in the DropDownList when the Edit Form Template was showed.

Basically, I resolved it adding a SqlDataSource for the DropDownList to load all posibles values:

<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:dbConnection %>" SelectCommand="SELECT id, tipo FROM dbo.tblTiposProducto where idFamilia = '315923C1-33BD-464F-AB19-E6C3DA329973'" />

Additionally, I had to use the ItemDataBound function of th RadGrid with the following code:

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)
            {
                GridEditableItem editedItem = e.Item as GridEditableItem;
                DropDownList _ddl = (DropDownList)e.Item.FindControl("ddFamilias");
                if (_ddl != null)
                {
                    _ddl.DataSource = this.SqlDataSource2;
                    _ddl.DataTextField = "tipo";
                    _ddl.DataValueField = "id";
                    _ddl.DataBind();
 
                    HiddenField _txtIdTipoProducto = (HiddenField)e.Item.FindControl("txtIdTipoProducto");
                    _ddl.SelectedIndex = _ddl.Items.IndexOf(_ddl.Items.FindByValue(_txtIdTipoProducto.Value));
                }
            }
 
        }


I hope it will be helpful to your problem.

Cheers.

David Ortega.



0
David
Top achievements
Rank 1
answered on 12 Feb 2015, 09:42 PM
Thanks David
Tags
Grid
Asked by
David
Top achievements
Rank 1
Answers by
davortsan
Top achievements
Rank 1
David
Top achievements
Rank 1
Share this question
or