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

How to update datatable/rows when using the built in editing

1 Answer 53 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 23 Sep 2008, 01:06 PM
Hi..
I'm using a grid bound to a data table. I'm also using the built in editting.
When I edit and then click the check to update my values do not update.
What code do I need to add to update the values in data table from the edited grid values.
thanks

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 24 Sep 2008, 04:25 AM
Hello Jon,

I suppose you are using an EditFormTemplate. If so you can try out the following code to update the edited values into the database.
aspx:
<EditFormSettings EditFormType="Template"
                <FormTemplate> 
                    <asp:TextBox ID="TextBox2"  runat="server"></asp:TextBox> 
                    <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> 
                    <asp:CheckBox ID="CheckBox2" AutoPostBack="true" runat="server" OnCheckedChanged="CheckBox2_CheckedChanged" /> 
                </FormTemplate>                    
                </EditFormSettings> 

cs:
protected void CheckBox2_CheckedChanged(object sender, EventArgs e) 
    { 
        foreach (GridEditFormItem formItem in RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem)) 
        { 
            //Get the primary key value  
            string CompanyID = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["CompanyID"].ToString(); 
            string CompanyName = (formItem.FindControl("TextBox2") as TextBox).Text; 
            string ContactName = (formItem.FindControl("TextBox3") as TextBox).Text; 
 
 
            SqlConnection.Open();             
            string updateQuery = "UPDATE Customers set CompanyName='" + CompanyName + "',ContactName='" + ContactName + "' where CompanyID='" + CompanyID + "'"; 
            SqlCommand.CommandText = updateQuery
            SqlCommand.Connection = SqlConnection
            SqlCommand.ExecuteNonQuery(); 
            SqlConnection.Close();  
            
        } 
    } 

For more information on manual update go through the folowing code library submission.
Manual Insert/Update/Delete

Princy.
Tags
Grid
Asked by
Jon
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or