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

Display EditColumn in top instead of Add New button

5 Answers 81 Views
Grid
This is a migrated thread and some comments may be shown as answers.
prathap
Top achievements
Rank 1
prathap asked on 22 Jun 2015, 03:33 PM

Hi,

 I have a Rad Grid used in my application. When i click "Add New" button, the edit column is displayed in the top and i can add new record. Is there a way i can hide the "Add New" button and display the Edit Column by default in the top always so that user can enter the value and click Insert. My Grid code as below,

 

<telerik:RadGrid ID="rgTest" runat="server" AllowPaging="True" AllowSorting="True"
                                AutoGenerateColumns="False" Width="97%" OnNeedDataSource="rgTest_NeedDataSource"
                                OnUpdateCommand="rgTest_UpdateCommand" OnDeleteCommand="rgTest_DeleteCommand"
                                OnInsertCommand="rgTest_InsertCommand" AllowAutomaticDeletes="true" Visible="true">
                                <PagerStyle Mode="NextPrevAndNumeric" />
                                <MasterTableView Width="100%" CommandItemDisplay="Top" EditMode="InPlace" DataKeyNames="ID"
                                    AllowAutomaticDeletes="true">
                                    <CommandItemSettings AddNewRecordText="Add New" ShowRefreshButton="false" />
                                    <Columns>
                                        <telerik:GridEditCommandColumn UniqueName="TestEdit">
                                        </telerik:GridEditCommandColumn>
                                        <telerik:GridTemplateColumn HeaderText="ID" Display="false" UniqueName="TestID">
                                            <ItemTemplate>
                                                <asp:Label runat="server" ID="lblID" Text='<%# Eval("ID") %>' />
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridTemplateColumn HeaderText="Names" UniqueName="TestName">
                                            <ItemTemplate>
                                                <%#DataBinder.Eval(Container.DataItem,"Name")%>
                                            </ItemTemplate>
                                            <EditItemTemplate>
                                                <telerik:RadComboBox runat="server" ID="rcbTestName" DataTextField="Name" DataValueField="ID">
                                                </telerik:RadComboBox>
                                            </EditItemTemplate>
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridButtonColumn CommandName="Delete" ButtonType="ImageButton" ImageUrl="~/Images/delete16x16.png"
                                            Text="Delete" ConfirmText="Are you sure you want to delete the selected row?">
                                        </telerik:GridButtonColumn>
                                    </Columns>
                                </MasterTableView>
                            </telerik:RadGrid>

5 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 25 Jun 2015, 10:49 AM
Hi,

In order to hide the Add New Record Button you should set the CommandItemSettings-ShowAddNewRecordButton property to false. If you would like to hide the CommandItem completely you can set the CommandItemDisplay property to None.

As for showing the Insert row at all times. You need to handle the Page_PreRender event and set the RadGrid in insert mode. In order for the configuration to work you should also rebind the grid. Note that this would result in requesting the same data twice.

The following code snippet illustrates the approach:


protected void Page_PreRender(object sender, EventArgs e)
{
    rgTest.MasterTableView.IsItemInserted = true;
    rgTest.Rebind();
}


I hope this helps.

Regards,
Viktor Tachev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
prathap
Top achievements
Rank 1
answered on 25 Jun 2015, 08:01 PM

Thanks. It works fine as i expected.

But i still have an issue. After i click insert, the Edit panel hides and only when i click delete it appears back. 

I tried adding the above line in insert command event also, nothing works.

0
Viktor Tachev
Telerik team
answered on 26 Jun 2015, 02:51 PM
Hi,

I have prepared a sample project that illustrates the approach. Please give it a try and see how it works for you.

Try to use similar logic and you should be able to implement the behavior you are looking for.

Regards,
Viktor Tachev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
prathap
Top achievements
Rank 1
answered on 07 Jul 2015, 08:53 PM

The code sample which you gave works perfectly when i have the grid in aspx page. But my grid is inside User Control and this sample did not work in my situation. Somehow, i have create an edit panel outside the grid and binds the grid after i click submit in my edit panel, so that solved my problem.

Thanks for your help. I can use this solution in future, if i use a grid in aspx page.

0
Viktor Tachev
Telerik team
answered on 08 Jul 2015, 02:25 PM
Hi,

The behavior you describe seems strange. The approach from the sample should work as expected regardless where the RadGrid is placed (User Control or Web Form).


With that said, I am glad that you have the issue resolved.


Regards,
Viktor Tachev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
prathap
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
prathap
Top achievements
Rank 1
Share this question
or