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

RadGrid There RadComboBox use FormTemplate edit control

3 Answers 146 Views
Grid
This is a migrated thread and some comments may be shown as answers.
tiger_ybz
Top achievements
Rank 1
tiger_ybz asked on 12 Jun 2010, 09:10 AM
 RadGrid There RadComboBox use FormTemplate edit control, automatic add, delete and update.
Click Edit when the RadComboBox can not be selected.
RadGrid and RadComboBox are two tables, the main foreign key relationship. How to RadComboBx select edit data. Thank you! ! !I use the Entity Data Source

Code:

<telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" 
            AllowAutomaticUpdates="True" DataSourceID="EntityDataSource1" GridLines="None" 
            OnItemUpdated="RadGrid1_ItemUpdated" OnInsertCommand="RadGrid1_InsertCommand" 
            OnItemCommand="RadGrid1_ItemCommand">  
            <MasterTableView AutoGenerateColumns="False" HorizontalAlign="NotSet" CommandItemDisplay="TopAndBottom" 
                DataKeyNames="DicID" DataSourceID="EntityDataSource1">  
                <Columns>  
                    <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">  
                    </telerik:GridEditCommandColumn>  
                    <telerik:GridBoundColumn DataField="DicID" HeaderText="DicID" ReadOnly="false" SortExpression="DicID" 
                        UniqueName="DicID">  
                    </telerik:GridBoundColumn>  
                    <telerik:GridBoundColumn DataField="DicDode" HeaderText="DicDode" SortExpression="DicDode" 
                        UniqueName="DicDode">  
                    </telerik:GridBoundColumn>  
                    <telerik:GridBoundColumn DataField="DicName" HeaderText="DicName" SortExpression="DicName" 
                        UniqueName="DicName">  
                    </telerik:GridBoundColumn>  
                    <telerik:GridBoundColumn DataField="DicRe" HeaderText="DicRe" SortExpression="DicRe" 
                        UniqueName="DicRe">  
                    </telerik:GridBoundColumn>  
                    <telerik:GridDropDownColumn DataField="d_DicType.DicTypeID" DataSourceID="EntityDataSource2" 
                        ListTextField="TypeName" ListValueField="DicTypeID" HeaderText="d_DicType.DicTypeID" 
                        SortExpression="d_DicType.DicTypeID" UniqueName="d_DicType.DicTypeID">  
                    </telerik:GridDropDownColumn>  
                    <telerik:GridButtonColumn HeaderText="Delete" ConfirmText="Delete this product?" 
                        ConfirmDialogType="RadWindow" ConfirmTitle="Delete" ButtonType="ImageButton" 
                        CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">  
                        <ItemStyle HorizontalAlign="Center" />  
                    </telerik:GridButtonColumn>  
                </Columns>  
                <EditFormSettings EditFormType="Template" ColumnNumber="2" CaptionDataField="RoleName">  
                    <EditColumn ButtonType="ImageButton" InsertText="Insert Order" UpdateText="Update record" 
                        UniqueName="EditCommandColumn1" CancelText="Cancel edit">  
                    </EditColumn>  
                    <FormTableStyle CellSpacing="0" CellPadding="2" Height="110px" BackColor="White" />  
                    <FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" BackColor="White" 
                        Width="100%" />  
                    <FormTableItemStyle Wrap="False"></FormTableItemStyle>  
                    <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>  
                    <FormTableButtonRowStyle HorizontalAlign="Right"></FormTableButtonRowStyle>  
                    <FormTemplate>  
                        <table align="center" border="2" cellpadding="2" cellspacing="1" style="width: 100%;
                            border-collapse: collapse;">  
                            <tr>  
                                <td style="width: 100px; height: 40px">  
                                    <telerik:RadTextBox ID="DicID" runat="server" Text='<%# Bind("DicID") %>' Width="150px" 
                                        Visible="false">  
                                    </telerik:RadTextBox>  
                                    DicDode:  
                                </td>  
                                <td style="height: 30px">  
                                    <telerik:RadTextBox ID="RadTextBox_UserName" runat="server" Text='<%# Bind("DicDode") %>'  
                                        Width="150px">  
                                    </telerik:RadTextBox>  
                                </td>  
                                <td style="width: 120px; height: 30px">  
                                    DicName:  
                                </td>  
                                <td style="height: 30px">  
                                    <telerik:RadTextBox ID="RadTextBox_LoginName" runat="server" Text='<%# Bind("DicName") %>'  
                                        Width="150px">  
                                    </telerik:RadTextBox>  
                                </td>  
                            </tr>  
                            <tr>  
                                <td style="width: 100px; height: 40px">  
                                    DicRe:  
                                </td>  
                                <td style="height: 30px">  
                                    <telerik:RadTextBox ID="RadTextBox3" runat="server" Text='<%# Bind("DicRe") %>' Width="150px">  
                                    </telerik:RadTextBox>  
                                </td>  
                                <td style="width: 120px; height: 30px">  
                                    DicTypeID:  
                                </td>  
                                <td style="height: 30px">  
                                    <telerik:RadComboBox ID="ComboBox1" runat="server" DataSourceID="EntityDataSource2" 
                                        DataTextField="TypeName" DataValueField="DicTypeID" AppendDataBoundItems="true" 
                                        SelectedValue='<%# Bind("d_DicType.DicTypeID") %>'>  
                                    </telerik:RadComboBox>  
                                </td>  
                            </tr>  
                            <tr>  
                                <td colspan="4" align="center">  
                                    <asp:Button ID="btnUpdate" runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'  
                                        Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' />  
                                    <asp:Button ID="btnCancel" runat="server" CausesValidation="False" CommandName="Cancel" 
                                        Text="Cancel" />  
                                </td>  
                            </tr>  
                        </table>  
                    </FormTemplate>  
                </EditFormSettings>  
            </MasterTableView>  
        </telerik:RadGrid>  
 
<asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=UnicornDBEntities" 
            DefaultContainerName="UnicornDBEntities" EnableDelete="True" EnableInsert="True" 
            EnableUpdate="True" EntitySetName="d_DicInfo" EntityTypeFilter="d_DicInfo">  
        </asp:EntityDataSource>  
 
<asp:EntityDataSource ID="EntityDataSource2" runat="server" ConnectionString="name=UnicornDBEntities" 
        DefaultContainerName="UnicornDBEntities" EnableDelete="True" EnableInsert="True" 
        EnableUpdate="True" EntitySetName="d_DicType">  
    </asp:EntityDataSource> 

3 Answers, 1 is accepted

Sort by
0
soft
Top achievements
Rank 1
answered on 13 Jun 2010, 01:22 AM

up!

 

 

 

0
WCRA Dev
Top achievements
Rank 1
answered on 23 Jun 2010, 10:44 PM
How do you access the value of the RadTextBox controls in Template Form?
0
Princy
Top achievements
Rank 2
answered on 24 Jun 2010, 07:07 AM
Hello,

I am not quite sure about your scenario. I guess you want to access the controls inside FormTemplate and to set the value from code behind, if so the following code might helpful to you.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
 { 
   if (e.Item is GridEditFormItem && e.Item.IsInEditMode) 
    { 
      GridEditFormItem edititem = (GridEditFormItem)e.Item; 
      RadTextBox txt = (RadTextBox)edititem.FindControl("RadTextBox_UserName");//access the RadTextBox in FormTemplate 
      string value = txt.Text; 
      RadComboBox combo = (RadComboBox)edititem.FindControl("ComboBox1");//access the RadComboBox in FormTemplate 
      //your code 
    } 
  } 

Thanks,
Princy.
Tags
Grid
Asked by
tiger_ybz
Top achievements
Rank 1
Answers by
soft
Top achievements
Rank 1
WCRA Dev
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or