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

Ideas needed - dynamic dropdown in form template

1 Answer 71 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin Price
Top achievements
Rank 1
Kevin Price asked on 08 Jun 2010, 07:17 PM
Hello,
Got a call today asking me to modify an app that is using a RadGrid->Form Template for data entry. The requested addition was that there be the addition of a dropdown for some existing items that when selected automatically populates the text boxes on the EditForm. This EditForm uses RadUpload as well - see below
<FormTemplate> 
                        <table id="Table1" cellspacing="1" cellpadding="1" width="350" style="height: 250px;" 
                            border="0"
                            <tr> 
                                <td> 
                                </td> 
                                <td> 
                                </td> 
                            </tr> 
                            <tr> 
                                <td> 
                                    Resource Type: 
                                </td> 
                                <td> 
                                    <asp:DropDownList ID="optResTypes" runat="server" DataSourceID="ResTypeDS" DataTextField="name" 
                                        DataValueField="name" AppendDataBoundItems="true" SelectedValue='<%# Bind("resourcetype_text") %>'
                                        <asp:ListItem Selected="True" Text="Select" Value=""></asp:ListItem> 
                                    </asp:DropDownList> 
                                </td> 
                            </tr> 
                            <tr> 
                                <td> 
                                    Title/Name: 
                                </td> 
                                <td> 
                                    <asp:TextBox ID="txtTitle" Text='<%# Bind("title") %>' runat="server"></asp:TextBox> 
                                </td> 
                            </tr> 
                            <tr> 
                                <td> 
                                    Description/URL: 
                                </td> 
                                <td> 
                                    <asp:TextBox ID="txtDescription" Text='<%# Bind( "field1") %>' runat="server"
                                    </asp:TextBox> 
                                </td> 
                            </tr> 
                            <tr> 
                                <td> 
                                    Additional Details: 
                                </td> 
                                <td> 
                                    <asp:TextBox ID="txtAddl" Text='<%# Bind( "field2") %>' runat="server"
                                    </asp:TextBox> 
                                </td> 
                            </tr> 
                            <tr> 
                                <td> 
                                    File Attachment: 
                                </td> 
                                <td> 
                                    <telerik:RadUpload MaxFileSize="5000000" runat="server" ID="FileUpload1"  
                                        AllowedFileExtensions=".zip,.jpg,.pptx,.docx,.doc,.xls,.pdf,.gif,.ppt,.txt,.csv,.png,.xlsx" 
                                         ControlObjectsVisibility="None" OverwriteExistingFiles="true"
                                    </telerik:RadUpload> 
                                     
                                </td> 
                            </tr> 
                             
                            <%--<tr> 
                                <td> 
                                    File Name: 
                                </td> 
                                <td> 
                                    <asp:TextBox ID="FileName" runat="server" Text='<%#Bind ("filename") %>'></asp:TextBox> 
                                </td> 
                            </tr>--%> 
                            <table style="width: 100%"
                                <tr> 
                                    <td align="right" colspan="2"
                                        <asp:Button ID="UpdateButton" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' 
                                            runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'
                                        </asp:Button>&nbsp; 
                                        <asp:Button ID="Button2" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel"
                                        </asp:Button> 
                                    </td> 
                                </tr> 
                            </table> 
                    </FormTemplate> 

Any ideas/examples would be great!

Thanks,
Kevin

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 09 Jun 2010, 11:05 AM
Hello Kevin,

You can populate the TextBoxes inside FormTemplate based on the selected value of DropDownList by attaching OnSelectedIndexChanged event to DropDownList. In the event handler, access the edit form using NamingContainer property of DropDownList and then access the TextBox using FindControl() method.

ASPX:
   <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="ResTypeDS" DataTextField="name" 
                            DataValueField="name" AppendDataBoundItems="true" SelectedValue='<%# Bind("resourcetype_text") %>' 
                            AutoPostBack="True" OnSelectedIndexChanged="optResTypes_SelectedIndexChanged"
                            <asp:ListItem Selected="True" Text="Select" Value=""></asp:ListItem> 
  </asp:DropDownList> 

C#:
  
 protected void optResTypes_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        DropDownList drlist = (DropDownList)sender; 
        string value = drlist.SelectedValue; 
        GridEditFormItem edititem = (GridEditFormItem)drlist.NamingContainer; 
        TextBox txt_Title = (TextBox)edititem.FindControl("txtTitle"); //access the TextBox 
        //populate TextBox based on SelectedValue of DropDownList  
    } 

Regards,
Shinu.


Tags
Grid
Asked by
Kevin Price
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or