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

Newbie

3 Answers 42 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sondang
Top achievements
Rank 1
Sondang asked on 11 Dec 2013, 05:02 AM
Hello....
my name is sondang, i am a newbie in Telerik.
Can the master told me to make CRUD(Creat, Update, Delete) by Telerik.
I might along with examples of its programs.

Thank you


3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 11 Dec 2013, 06:26 AM
Hi Sondang,

If you want to know how CRUD operation is performed in Telerik, please go through this demo on Grid - Automatic Operations for automatic operation and Grid - Manual CRUD Operations for manual operations on Grid.

Thanks,
Princy
0
Sondang
Top achievements
Rank 1
answered on 11 Dec 2013, 06:45 AM
I have tried but found the problem
could you give simple program
please, i wanna try
0
Princy
Top achievements
Rank 2
answered on 12 Dec 2013, 03:28 AM
Hi Sondang,

Below is a sample code snippet for manual CRUD operation, please try:

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource" AutoGenerateColumns="False" AllowPaging="true" OnUpdateCommand="RadGrid1_UpdateCommand" OnInsertCommand="RadGrid1_InsertCommand" OnDeleteCommand="RadGrid1_DeleteCommand" PageSize="15">           
      <MasterTableView  DataKeyNames="OrderID" CommandItemDisplay="Top">           
         <Columns>
        <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn"
         ConfirmText="Delete" ConfirmDialogType="RadWindow" />
        <telerik:GridBoundColumn HeaderText="OrderID" DataField="OrderID" UniqueName="OrderID" />
        <telerik:GridBoundColumn HeaderText="EmployeeID" DataField="EmployeeID" UniqueName="EmployeeID" />
        <telerik:GridBoundColumn HeaderText="OrderDate" DataField="OrderDate" UniqueName="OrderDate" />
        <telerik:GridBoundColumn HeaderText="ShipName" DataField="ShipName" UniqueName="ShipName" />
        <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" />
       </Columns>
    </MasterTableView>
</telerik:RadGrid>

C#:
public static string connection = WebConfigurationManager.ConnectionStrings["Northwind_newConnectionString3"].ConnectionString;
SqlConnection conn = new SqlConnection(connection);
DataTable dt1 = new DataTable();
    
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    string selectQuery1 = "SELECT [OrderID], [CustomerID], [EmployeeID], [OrderDate], [ShipName] FROM [Orders]" ;
    SqlDataAdapter adapter1 = new SqlDataAdapter(selectQuery1, conn);
    conn.Open();
    adapter1.Fill(dt1);
    conn.Close();
    RadGrid1.DataSource = dt1;             
}
 
protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
{
    GridEditableItem edit = (GridEditableItem)e.Item;
    string OrderID = edit.GetDataKeyValue("OrderID").ToString(); 
    try
    {           
        TextBox txt = (TextBox)edit["EmployeeID"].Controls[0];    
        TextBox txt1 = (TextBox)edit["OrderDate"].Controls[0];
        TextBox txt2 = (TextBox)edit["ShipName"].Controls[0];
        conn.Open();
        string query = "UPDATE Orders SET EmployeeID ='" + txt.Text + "', OrderDate='" + txt1.Text + "',ShipName='" + txt2.Text + "' WHERE OrderID = '" + OrderID + "'";
        SqlCommand cmd = new SqlCommand(query, conn);
        cmd.ExecuteNonQuery();
        conn.Close();   
    }
    catch (Exception ex)
    {       
    }  
}
protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)
{         
  try
    {
     string value = RadComboBox1.SelectedValue;
     GridEditableItem edit = (GridEditableItem)e.Item; 
     TextBox tx = (TextBox)edit["OrderID"].Controls[0];
     TextBox txt = (TextBox)edit["EmployeeID"].Controls[0];
     TextBox txt1 = (TextBox)edit["OrderDate"].Controls[0];
     TextBox txt2 = (TextBox)edit["ShipName"].Controls[0];        
     conn.Open();
     string query = "INSERT into Orders (OrderID,EmployeeID,OrderDate,ShipName) VALUES ('" + tx.Text + "','" + txt.Text + "','" + txt1.Text + "','" + txt2.Text + "')";
     SqlCommand cmd = new SqlCommand(query, conn);
     cmd.ExecuteNonQuery();
     conn.Close();        
   }
 catch (Exception ex)
   {          
   }   
}
protected void RadGrid1_DeleteCommand(object sender, GridCommandEventArgs e)
{
   try
   {
    GridDataItem edit = (GridDataItem)e.Item;
    string OrderID = edit.GetDataKeyValue("OrderID").ToString();
    conn.Open();
    string query = "DELETE from Orders Where OrderID = '" + OrderID + "'";
    SqlCommand cmd = new SqlCommand(query, conn);
    cmd.ExecuteNonQuery();
    conn.Close(); 
   }
  catch (Exception ex)
   
   }       
}

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