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

Radgrid is disappeared after clicking on the "Add New Record" error

2 Answers 102 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Newkid
Top achievements
Rank 1
Newkid asked on 11 Aug 2012, 03:50 AM

do you have any ideas?  below is my code.
Thanks!


2 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 11 Aug 2012, 09:18 AM
Sorry by mistake.
0
Jayesh Goyani
Top achievements
Rank 2
answered on 12 Aug 2012, 04:02 PM
Hello,

Please check below code snippet.

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" OnItemDataBound="RadGrid1_ItemDataBound"
           OnNeedDataSource="RadGrid1_NeedDataSource">
           <MasterTableView CommandItemDisplay="Top" DataKeyNames="ID" EditMode="InPlace">
               <Columns>
                   <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                   </telerik:GridBoundColumn>
                   <telerik:GridTemplateColumn>
                       <ItemTemplate>
                           <asp:Label ID="Label1" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
                       </ItemTemplate>
                       <EditItemTemplate>
                           <asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("Name") %>'></asp:TextBox>
                       </EditItemTemplate>
                   </telerik:GridTemplateColumn>
                   <telerik:GridEditCommandColumn>
                   </telerik:GridEditCommandColumn>
               </Columns>
           </MasterTableView>
       </telerik:RadGrid>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            dynamic data = new[] {
              new { ID = 1, Name ="name1"},
              new { ID = 2, Name = "name2"},
              new { ID = 3, Name = "name3"},
              new { ID = 4, Name = "Name4"},
               new { ID = 5, Name ="name5"}
            };
            RadGrid1.DataSource = data;
        }
 
        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item.IsInEditMode && e.Item is GridEditableItem && e.Item is GridDataInsertItem)
            {
                // Insert mode
 
                GridEditableItem item = e.Item as GridEditableItem;
                (item["ID"].Controls[0] as TextBox).Text = "Your ID";
                (item.FindControl("TextBox1") as TextBox).Text = "Your Name";
            }
 
        }

Please try with above code snippet and you may get how so set default value for insert.

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Newkid
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or