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

RadGrid and Update in Database ( Datasource Object )

1 Answer 93 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ernandes
Top achievements
Rank 1
Ernandes asked on 02 Mar 2009, 12:38 PM
Hi there,
I am using RadGrid however, I am having difficulties to make it update the information of the Database.

The scenario I have is this:

I created a DataSource object and a class with the components (insert, select, delete and update)

[DataObjectMethod (DataObjectMethodType.Select)]
[DataObjectMethod (DataObjectMethodType.Insert)]
[DataObjectMethod (DataObjectMethodType.Update)]
[DataObjectMethod (DataObjectMethodType.Delete)]

I made reference to the component, and Select functions correctly, but not the other operations.

In a key MasterTableView registered: datakeynames = "id_menu_esquerdo" which is my primary key in the Database, but when I try to change something, nothing happens, what can be wrong?
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True"  
        AutoGenerateDeleteColumn="True" AutoGenerateEditColumn="True"  
        DataSourceID="ObjectDataSource1" GridLines="None"
<MasterTableView autogeneratecolumns="False" clientdatakeynames="id_menu_esquerdo"  
            datakeynames="id_menu_esquerdo" datasourceid="ObjectDataSource1"
<RowIndicatorColumn Visible="False"
<HeaderStyle Width="20px"></HeaderStyle> 
</RowIndicatorColumn> 
 
<ExpandCollapseColumn Visible="False" Resizable="False"
<HeaderStyle Width="20px"></HeaderStyle> 
</ExpandCollapseColumn> 
 
    <Columns> 
        <telerik:GridBoundColumn DataField="id_menu_esquerdo" DataType="System.Int32"  
            HeaderText="id_menu_esquerdo" SortExpression="id_menu_esquerdo"  
            UniqueName="id_menu_esquerdo"
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="Nome_menu_esquerdo"  
            HeaderText="Nome_menu_esquerdo" SortExpression="Nome_menu_esquerdo"  
            UniqueName="Nome_menu_esquerdo"
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="menu_esquerdo_link"  
            HeaderText="menu_esquerdo_link" SortExpression="menu_esquerdo_link"  
            UniqueName="menu_esquerdo_link"
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="menu_esquerdo_ordem"  
            DataType="System.Int32" HeaderText="menu_esquerdo_ordem"  
            SortExpression="menu_esquerdo_ordem" UniqueName="menu_esquerdo_ordem"
        </telerik:GridBoundColumn> 
    </Columns> 
 
<EditFormSettings> 
<PopUpSettings ScrollBars="None"></PopUpSettings> 
</EditFormSettings> 
</MasterTableView> 
    </telerik:RadGrid> 

More...

[DataObjectMethod(DataObjectMethodType.Update)] 
        public static void AlterarItemMenuE(ItensMenu_E_Modelos ItensMenu) 
        { 
            using (SqlConnection conn = Banco.ObterConexao()) 
            { 
                conn.Open(); 
 
                using (SqlCommand cmd = new SqlCommand("UPDATE [tbl_web_MenuE] set Nome_menu_esquerdo = @Nome_menu_esquerdo, menu_esquerdo_ordem = @menu_esquerdo_ordem, menu_esquerdo_link = @menu_esquerdo_link WHERE id_menu_esquerdo = @id_menu_esquerdo", conn)) 
                { 
                    cmd.Parameters.AddWithValue("@id_menu_esquerdo", Convert.ToInt32(ItensMenu.id_menu_esquerdo)); 
                    cmd.Parameters.AddWithValue("@Nome_menu_esquerdo", Convert.ToString(ItensMenu.Nome_menu_esquerdo)); 
                    cmd.Parameters.AddWithValue("@menu_esquerdo_ordem", Convert.ToInt32(ItensMenu.menu_esquerdo_ordem)); 
                    cmd.Parameters.AddWithValue("@menu_esquerdo_link", Convert.ToString(ItensMenu.menu_esquerdo_link)); 
                    cmd.ExecuteNonQuery(); 
                } 
 
            } 
        } 

when I use the DataGridView's own VisualStudio everything works correctly, would help one to use the resources of the RadGrid
Best Regards

1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 05 Mar 2009, 07:20 AM
Hello Ernandes,

I reviewed the code and it looks correct. However, if the issue persists, you can open a formal support ticket, and send us a small working project, demonstrating your setup, and the discrepancy at hand, for additional testing.

Sincerely yours,
Yavor
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.
Tags
Grid
Asked by
Ernandes
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or