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

[Solved] RadGrid EditForm Template

3 Answers 171 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joan
Top achievements
Rank 1
Joan asked on 11 Mar 2013, 12:30 PM
Hello everybody!

I have a problem and I dont know how to resolve it.
I have a grid, in the grid I have some columns. When the page loads I want to appear the records of the grid but also the template to add new records, also has the link to add a new record, to edit and to remove (this two in each row of the records).
The template doesnt have all the fields on my table. But when I load the page I need to bind combos on my template and then save those values.
Here is my grid aspx:

<

                    <telerik:RadGrid ID="RadGridArticles" runat="server" AutoGenerateColumns="false" GridLines="None" OnNeedDataSource="RadGridArticles_NeedDataSource" OnInsertCommand="RadGridArticles_InsertCommand" OnDeleteCommand="RadGridArticles_DeleteCommand" OnUpdateCommand="RadGridArticles_UpdateCommand">
                        <MasterTableView DataKeyNames="Id" InsertItemDisplay="top" CommandItemDisplay="Top">
                            <CommandItemSettings AddNewRecordText="Add new record" ShowRefreshButton="false" />
                            <Columns>
                                <telerik:GridBoundColumn HeaderText="Article Name" DataField="Name"></telerik:GridBoundColumn>
                                <telerik:GridNumericColumn HeaderText="Amount" DataField="ArticleAmount"></telerik:GridNumericColumn>
                                <telerik:GridNumericColumn HeaderText="Price" DataField="ArticlePrice" NumericType="Currency" DecimalDigits="2"></telerik:GridNumericColumn>
                                <telerik:GridBoundColumn HeaderText="Category" DataField="CategoryName"></telerik:GridBoundColumn>
                                <telerik:GridTemplateColumn HeaderText="Category THF">
                                    <ItemTemplate>
                                        <%#  Eval("CategoryName")%> <%#  Eval("THFDescription")%>
                                    </ItemTemplate>

                                </telerik:GridTemplateColumn>
                                <telerik:GridButtonColumn ButtonType="PushButton" Text="Add" CommandName="Edit"></telerik:GridButtonColumn>
                                <telerik:GridButtonColumn ButtonType="PushButton" Text="Remove" CommandName="Delete"></telerik:GridButtonColumn>
                            </Columns>
                            <EditFormSettings EditFormType="Template">
                                <FormTemplate>
                                    <div style="padding: 10px;">
                                        <div>
                                            <asp:Label ID="LabelArticle" runat="server"  Text="Article"></asp:Label>
                                            <telerik:RadTextBox ID="RadTextBoxArticle"  runat="server"  AppendDataBoundItems="true" DataTextField="Name" DataValueField="Id" ></telerik:RadTextBox>
                                        </div>
                                        <div>
                                            <asp:Label ID="LabelArticleAmount" runat="server" Text="Amount" ></asp:Label>
                                            <telerik:RadNumericTextBox ID="RadNumericTextBoxAmount" runat="server" AppendDataBoundItems="true" Type="Currency"></telerik:RadNumericTextBox>
                                        </div>
                                        <div>
                                            <asp:Label ID="LabelCateg" runat="server" Text="Category" ></asp:Label>
                                            <telerik:RadComboBox ID="RadComboBoxCateg" runat="server" Type="Number" DataValueField="IdCategory" DataTextField="CategoryName" ></telerik:RadComboBox>
                                        </div>
                                        <div>
                                            <asp:Label ID="LabelTHF" runat="server" Text="THF" ></asp:Label>
                                            <telerik:RadComboBox ID="RadComboBoxTHF" runat="server" Type="Currency"  DataValueField="IdTHF" DataTextField="THFDescription" AppendDataBoundItems="true"></telerik:RadComboBox>
                                        </div>
                                        <div>
                                            <asp:Button ID="ButtonUpdate"  runat="server" CommandName="Update"  ></asp:Button>
                                            <asp:Button ID="ButtonInsert"  runat="server" CommandName="PerformInsert" ></asp:Button>
                                        </div>
                           
                                </FormTemplate>
                            </EditFormSettings>
                        </MasterTableView>
                    </telerik:RadGrid>

>


I tried to load the combo like this but nothing. Hopw someone can help me!
Thanks telerik team!!!

 

protected void RadGridExpensesLines_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)

{

 

if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode))

{

GridEditFormItem editform = (GridEditFormItem)e.Item;

RadComboBox ComboBox = (RadComboBox)editform.FindControl("RadComboBoxTHF");
Combobox.datasource=MYDATASOURCE;

ComboBoxBTW.DataBind();

 

}

}

3 Answers, 1 is accepted

Sort by
0
Joan
Top achievements
Rank 1
answered on 11 Mar 2013, 02:00 PM
Please telerik team could you please help me with this? How could I access to my template´s controls from my

InsertCommand method for example, or anyother place but OnItemDataBoundHandler.
Thanks!!!

0
Radoslav
Telerik team
answered on 14 Mar 2013, 09:32 AM
Hello Joan,

The ItemDataBound event is the right place for achieve the desired functionality. Why do not you want to use it? Additionally I am sending you a simple example based on your code which demonstrates that on RadGridArticles_ItemDataBound event the RadComboBxo is bound as expected. Please check it out and let me know if it helps you.

Looking forward for your reply.

All the best,
Radoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Joan
Top achievements
Rank 1
answered on 18 Mar 2013, 09:39 AM
Hi Radoslav!
Thanks for your code example, it hepls me a lot. I finally used the ItemDataBound, and also to set the values to edit when selected a row just checking this:

if

 

 

(e.Item is GridEditFormItem && e.Item.IsInEditMode && !e.Item.OwnerTableView.IsItemInserted)


Thanks again for your help!!!
Thanks telerik team!
Tags
Grid
Asked by
Joan
Top achievements
Rank 1
Answers by
Joan
Top achievements
Rank 1
Radoslav
Telerik team
Share this question
or