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

Basic CRUD Operation Programmatically

1 Answer 31 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shubhadeep
Top achievements
Rank 1
Shubhadeep asked on 29 Aug 2013, 02:54 PM
Hello,

I am very new in telerik. I have an application where i have added a radgrid. I am displaying data from the code behind with the dataset. But now i want do add,edit,delete from the code behind.How can i do that? also when i am adding ajaxmanager then no data is displaying. please help me.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 30 Aug 2013, 03:32 AM
Hi Shubhadeep,

Please try the following code snippet to perform Manual CRUD operation.

ASPX:
<telerik:RadAjaxManager ID="RadAjaxManager1" EnableAJAX="true" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadGrid1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1">
                </telerik:AjaxUpdatedControl>
                <telerik:AjaxUpdatedControl ControlID="Label1" LoadingPanelID="RadAjaxLoadingPanel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
</telerik:RadAjaxLoadingPanel>
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource" AllowPaging="true" OnUpdateCommand="RadGrid1_UpdateCommand" OnInsertCommand="RadGrid1_InsertCommand"     OnDeleteCommand="RadGrid1_DeleteCommand"
    <MasterTableView DataKeyNames="OrderID" CommandItemDisplay="Top">     
        <Columns>
            <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn" />
            <telerik:GridBoundColumn HeaderText="OrderID" DataField="OrderID" ReadOnly="True"
                UniqueName="OrderID" />
            <telerik:GridBoundColumn HeaderText="EmployeeID" DataField="EmployeeID" UniqueName="EmployeeID" />            
            <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" />
        </Columns>
    </MasterTableView>
</telerik:RadGrid>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

C#:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
   {
      //Populate the radgrid   
   }
 
   protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
   {      
       string OrderID = edit.GetDataKeyValue("OrderID").ToString();    
       try
       {    
           GridEditableItem edit = (GridEditableItem)e.Item;      
           TextBox txt = (TextBox)edit["EmployeeID"].Controls[0];//Access the bound column value in edit mode         
           
           //Code to Update
           Label1.Text = "Product with ID " + OrderID + " is updated!";
       }
       catch (Exception ex)
       {
           Label1.Text = "Product with ID " + OrderID + " cannot be updated. " ;
       }       
 
   }
   protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)
   {     
   //Code to insert
   }
  
   protected void RadGrid1_DeleteCommand(object sender, GridCommandEventArgs e)
   {
     //Code to delete
  }

Thanks,
Princy
Tags
Grid
Asked by
Shubhadeep
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Share this question
or