Rank: Member Groups: Member
Joined: 10/24/2010 Posts: 14
|
Hello, I tried to use the grid control to insert/update and delete data from my database, but the only what I’m able to do is displaying data in the grid control, I activate the edit and delete command but when I change data and I click update or click the button the data aren’t changed on database Could you please help me to perform the update and the delete action using your Grid control and sqldatasource. Here the page I’m using, Thanks in advance, Mohamed
Code: HTML/ASPX
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default_grid_test.aspx.cs" Inherits="Default_grid_test" %>
<%@ Register assembly="EO.Web" namespace="EO.Web" tagprefix="eo" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<eo:Grid ID="Grid1" runat="server" BorderColor="#C7D1DF"
BorderWidth="1px" ColumnHeaderAscImage="00050303"
ColumnHeaderDescImage="00050304" ColumnHeaderDividerImage="00050302"
FixedColumnCount="1" Font-Bold="False" Font-Italic="False" Font-Names="Verdana"
Font-Overline="False" Font-Size="9pt" Font-Strikeout="False"
Font-Underline="False" GridLineColor="199, 209, 223" GridLines="Both"
Height="200px" ItemHeight="19" RunningMode="Callback" Width="504px"
AllowColumnReorder="True" AllowNewItem="True" DataSourceID="SqlDataSource1">
<FooterStyle CssText="padding-bottom:4px;padding-left:4px;padding-right:4px;padding-top:4px;" />
<ColumnTemplates>
<eo:TextBoxColumn>
<TextBoxStyle CssText="BORDER-RIGHT: #7f9db9 1px solid; PADDING-RIGHT: 2px; BORDER-TOP: #7f9db9 1px solid; PADDING-LEFT: 2px; FONT-SIZE: 8.75pt; PADDING-BOTTOM: 1px; MARGIN: 0px; BORDER-LEFT: #7f9db9 1px solid; PADDING-TOP: 2px; BORDER-BOTTOM: #7f9db9 1px solid; FONT-FAMILY: Tahoma" />
</eo:TextBoxColumn>
<eo:MaskedEditColumn>
<MaskedEdit ControlSkinID="None"
TextBoxStyle-CssText="BORDER-RIGHT: #7f9db9 1px solid; PADDING-RIGHT: 2px; BORDER-TOP: #7f9db9 1px solid; PADDING-LEFT: 2px; PADDING-BOTTOM: 1px; MARGIN: 0px; BORDER-LEFT: #7f9db9 1px solid; PADDING-TOP: 2px; BORDER-BOTTOM: #7f9db9 1px solid; font-family:Courier New;font-size:8pt;">
</MaskedEdit>
</eo:MaskedEditColumn>
</ColumnTemplates>
<ColumnHeaderStyle CssText="background-image:url('00050301');padding-left:8px;padding-top:2px;font-weight: bold;color:white;" />
<ItemStyles>
<eo:GridItemStyleSet>
<ItemStyle CssText="background-color: white" />
<ItemHoverStyle CssText="background-image: url(00050206); background-repeat: repeat-x" />
<SelectedStyle CssText="background-image: url(00050207); background-repeat: repeat-x" />
<CellStyle CssText="padding-left:8px;padding-top:2px; color:#336699;white-space:nowrap;" />
</eo:GridItemStyleSet>
</ItemStyles>
<Columns>
<eo:RowNumberColumn>
</eo:RowNumberColumn>
<eo:TextBoxColumn DataField="NOM_REGION" HeaderText="Région">
</eo:TextBoxColumn>
<eo:TextBoxColumn DataField="PAYS" HeaderText="Pays">
</eo:TextBoxColumn>
<eo:EditCommandColumn>
</eo:EditCommandColumn>
<eo:DeleteCommandColumn>
</eo:DeleteCommandColumn>
</Columns>
</eo:Grid>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ircam_corpusConnectionString %>"
DeleteCommand="DELETE FROM [REGION] WHERE [ID_REGION] = @ID_REGION"
InsertCommand="INSERT INTO [REGION] ([ID_REGION], [NOM_REGION], [PAYS]) VALUES (@ID_REGION, @NOM_REGION, @PAYS)"
SelectCommand="SELECT * FROM [REGION]"
UpdateCommand="UPDATE [REGION] SET [NOM_REGION] = @NOM_REGION, [PAYS] = @PAYS WHERE [ID_REGION] = @ID_REGION">
<DeleteParameters>
<asp:Parameter Name="ID_REGION" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="NOM_REGION" Type="String" />
<asp:Parameter Name="PAYS" Type="String" />
<asp:Parameter Name="ID_REGION" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="ID_REGION" Type="String" />
<asp:Parameter Name="NOM_REGION" Type="String" />
<asp:Parameter Name="PAYS" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</asp:Content>
Code: C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default_grid_test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Grid1.DataSource = SqlDataSource1;
Grid1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
}
}
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
The Grid does not automatically save changes back to your data source. You can examine the Grid's ChangedItems, AddedItems and DeletedItems collection in your event handler to save the changes. You can also handle the Grid's ItemAdded, ItemChanged and ItemDeleted event to update your data source.
Thanks!
|