This is a migrated thread and some comments may be shown as answers.
Show the Add New Record row by default
7 Answers 203 Views
This is a migrated thread and some comments may be shown as answers.
ric c
Top achievements
Rank 1
ric c asked on 19 Aug 2009, 07:29 AM
Hi, I have a grid that uses the [Add new record] button in the Command row. I click the button and the insert row appears (in-line) and all works great.

My question is how do I set the grid so that this command row is showing when the grid first loads and always shows?

Thanks

7 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 19 Aug 2009, 07:50 AM
Hello,

You can try out the following code to always set the grid in Insert mode:
c#:
 protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
 
        RadGrid1.MasterTableView.IsItemInserted = true
        RadGrid1.Rebind(); 
   } 

Thanks
Princy.
0
ric c
Top achievements
Rank 1
answered on 19 Aug 2009, 08:00 AM
Perfect! Thanks.

One last question, how do I remove the 'cancel' link from this row?
0
Vlad
Telerik team
answered on 19 Aug 2009, 08:19 AM
Hi ric c,

You can define your own CommandItemTemlate.

All the best,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
ric c
Top achievements
Rank 1
answered on 19 Aug 2009, 09:11 AM
can you point me in the right direction, I can see how to alter items using 

<

 

CommandItemSettings AddNewRecordText="Add New Chapter" /> for example, but how do I create a CommandItemTemplate?

Thanks

 

 

 

 

 

0
Shinu
Top achievements
Rank 1
answered on 19 Aug 2009, 09:38 AM
Hi,

I'm not sure if you are using an EditCommandColumn or anAutoGenerateEditColumn? For either of the columns you can access theCancel button and hide it as shown below:
protected void RadGrid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridDataInsertItem && e.Item.OwnerTableView.IsItemInserted) 
        { 
            GridDataInsertItem dataItem = (GridDataInsertItem)e.Item; 
           ((LinkButton)dataItem["EditColumnUniqueName"].Controls[2]).Visible = false;//for EditCommandColumn 
           // where EditColumnUniqueName is the column's UniqueName which should be manually set 
           ((LinkButton)dataItem["AutoGeneratedEditColumn"].Controls[2]).Visible = false;//for AutoGenerateEditColumn  
           //where AutoGeneratedEditColumn is the column's UniqueName that is predefined automatically          
        } 
   }  

Thanks
Shinu.
0
ric c
Top achievements
Rank 1
answered on 19 Aug 2009, 10:43 AM

Hi Thanks for the reply,

this is the grid I'm using:

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" AllowAutomaticInserts="True" 
                                    OnUpdateCommand="RadGrid1_UpdateCommand" OnNeedDataSource="RadGrid1_NeedDataSource" 
                                    OnInsertCommand="RadGrid1_InsertCommand" GridLines="None" Width="98%" OnItemDataBound="RadGrid1_OIDB" 
                                    OnDataBinding="RadGrid1_DataBinding" OnItemCreated="RadGrid1_ItemCreated" OnPreRender="RadGrid1_PreRender">  
                                    <ItemStyle HorizontalAlign="Center" /> 
                                    <AlternatingItemStyle HorizontalAlign="Center" />                                      
                                    <MasterTableView EditMode="InPlace" DataKeyNames="ID" NoMasterRecordsText="No Chapters exists yet">  
                                        <Columns> 
                                            <telerik:GridTemplateColumn HeaderText="Start Page" UniqueName="TemplateColumn">  
                                                <ItemTemplate> 
                                                    <%# DataBinder.Eval(Container.DataItem, "StartPage") %> 
                                                </ItemTemplate> 
                                                <EditItemTemplate> 
                                                    <telerik:RadNumericTextBox Width="60px" ID="TbEditStartPage" runat="server" DbValue='<%# Bind("StartPage")%>' 
                                                        Type="Number" MinValue="0" Value="0" MaxValue='<%# GetMaxPageValue() %>' ShowSpinButtons="True">  
                                                        <NumberFormat DecimalDigits="0" /> 
                                                    </telerik:RadNumericTextBox> 
                                                </EditItemTemplate> 
                                                <HeaderStyle Width="70px" /> 
                                            </telerik:GridTemplateColumn> 
                                            <telerik:GridTemplateColumn HeaderText="End Page" UniqueName="TemplateColumn1">  
                                                <ItemTemplate> 
                                                    <%# DataBinder.Eval(Container.DataItem, "EndPage") %> 
                                                </ItemTemplate> 
                                                <EditItemTemplate> 
                                                    <telerik:RadNumericTextBox Width="60px" ID="TbEditEndPage" runat="server" DbValue='<%# Bind("EndPage")%>' 
                                                        Type="Number" MinValue="0" MaxValue='<%# GetMaxPageValue() %>' Value="0" ShowSpinButtons="True">  
                                                        <NumberFormat DecimalDigits="0" /> 
                                                    </telerik:RadNumericTextBox> 
                                                </EditItemTemplate> 
                                                <HeaderStyle Width="70px" /> 
                                            </telerik:GridTemplateColumn> 
                                            <telerik:GridTemplateColumn HeaderText="Chapter Name" UniqueName="TemplateColumn2">  
                                                <ItemTemplate> 
                                                    <%# DataBinder.Eval(Container.DataItem, "ChapterName") %> 
                                                </ItemTemplate> 
                                                <EditItemTemplate> 
                                                    <asp:TextBox ID="TbEditChapterName" runat="server" Text='<%# Bind("ChapterName")%>'></asp:TextBox> 
                                                </EditItemTemplate> 
                                                <ItemStyle HorizontalAlign="Left" /> 
                                            </telerik:GridTemplateColumn> 
                                            <telerik:GridEditCommandColumn HeaderText="Edit">  
                                                <HeaderStyle Width="60px" /> 
                                            </telerik:GridEditCommandColumn>                                             
                                        </Columns> 
                                        <EditFormSettings> 
                                            <EditColumn UniqueName="EditCommandColumn1">  
                                            </EditColumn> 
                                        </EditFormSettings> 
                                        <CommandItemSettings AddNewRecordText="Add New Chapter" /> 
                                          
                                    </MasterTableView> 
                                </telerik:RadGrid> 
protected void RadGrid1_PreRender(object sender, EventArgs e)  
        {  
            RadGrid1.MasterTableView.IsItemInserted = true;  
            RadGrid1.Rebind();   
        } 

I tried your code but it can't find the column?

0
Sameer Alibhai
Top achievements
Rank 1
answered on 25 Sep 2009, 09:10 PM
CommandItemTemplate is inside MasterTableView

 <radG:RadGrid ID="RadGrid1" AllowAutomaticInserts="false" AllowPaging="True" 
                DataSourceID="ObjectDataSource1" runat="server"
                <MasterTableView DataKeyNames="ID" CommandItemDisplay="Bottom"
                <CommandItemTemplate> 
                </CommandItemTemplate> 
                </MasterTableView>               
            </radG:RadGrid> 

Tags
Grid
Asked by
ric c
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
ric c
Top achievements
Rank 1
Vlad
Telerik team
Shinu
Top achievements
Rank 1
Sameer Alibhai
Top achievements
Rank 1
Share this question
or