Display EditColumn in top instead of Add New button

6 posts, 0 answers
  1. prathap
    prathap avatar
    3 posts
    Member since:
    Dec 2011

    Posted 22 Jun 2015 Link to this post

    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>

  2. Viktor Tachev
    Admin
    Viktor Tachev avatar
    2342 posts

    Posted 25 Jun 2015 Link to this post

    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
  3. prathap
    prathap avatar
    3 posts
    Member since:
    Dec 2011

    Posted 25 Jun 2015 in reply to Viktor Tachev Link to this post

    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.

  4. Viktor Tachev
    Admin
    Viktor Tachev avatar
    2342 posts

    Posted 26 Jun 2015 Link to this post

    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
  5. prathap
    prathap avatar
    3 posts
    Member since:
    Dec 2011

    Posted 07 Jul 2015 in reply to Viktor Tachev Link to this post

    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.

  6. Viktor Tachev
    Admin
    Viktor Tachev avatar
    2342 posts

    Posted 08 Jul 2015 Link to this post

    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
Back to Top