I have used the Ultrawebgrid for quite a while, however I cannot get a (any) simple bound data grid to perform any updates/adds/deletes. It look like it does but no updates are performed on the database. I have tried lots of things and what I have below is, I believe, following the absolute basic example, but this doesn't work, either.
The database is read/write. I have several other forms where I do updates via code. I use SQLDatasources elsewhere.
Nothing seems to postback the grid in any way. I make changes on the web page but nothing happens. I have, in one of the many other tests I have done, trapped the SQLDataSource events but they never get triggered.
Any clues please.
Partial Class TestPage2 Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Me.ultrawebgrid1.databind() End SubEnd Class
<body> <form id="form1" runat="server"> <div> </div> <igtbl:UltraWebGrid ID="UltraWebGrid1" runat="server" DataKeyField="UnitType" DataMember="DefaultView" DataSourceID="SqlDataSource1" Height="200px" Width="325px"> <Bands> <igtbl:UltraGridBand DataKeyField="UnitType"> <AddNewRow View="NotSet" Visible="NotSet"> </AddNewRow> <Columns> <igtbl:UltraGridColumn BaseColumnName="UnitType" IsBound="True" Key="UnitType"> <Header Caption="UnitType"> </Header> </igtbl:UltraGridColumn> </Columns> </igtbl:UltraGridBand> </Bands> <DisplayLayout AllowAddNewDefault="Yes" AllowColSizingDefault="Free" AllowColumnMovingDefault="OnServer" AllowDeleteDefault="Yes" AllowSortingDefault="OnClient" AllowUpdateDefault="Yes" BorderCollapseDefault="Separate" HeaderClickActionDefault="SortMulti" Name="UltraWebGrid1" RowHeightDefault="20px" RowSelectorsDefault="No" SelectTypeRowDefault="Extended" StationaryMargins="Header" StationaryMarginsOutlookGroupBy="True" TableLayout="Fixed" Version="4.00" ViewType="OutlookGroupBy"> <FrameStyle BackColor="Window" BorderColor="InactiveCaption" BorderStyle="Solid" BorderWidth="1px" Font-Names="Microsoft Sans Serif" Font-Size="8.25pt" Height="200px" Width="325px"> </FrameStyle> <Pager MinimumPagesForDisplay="2"> <PagerStyle BackColor="LightGray" BorderStyle="Solid" BorderWidth="1px"> <BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" WidthTop="1px" /> </PagerStyle> </Pager> <EditCellStyleDefault BorderStyle="None" BorderWidth="0px"> </EditCellStyleDefault> <FooterStyleDefault BackColor="LightGray" BorderStyle="Solid" BorderWidth="1px"> <BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" WidthTop="1px" /> </FooterStyleDefault> <HeaderStyleDefault BackColor="LightGray" BorderStyle="Solid" HorizontalAlign="Left"> <BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" WidthTop="1px" /> </HeaderStyleDefault> <RowStyleDefault BackColor="Window" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px" Font-Names="Microsoft Sans Serif" Font-Size="8.25pt"> <Padding Left="3px" /> <BorderDetails ColorLeft="Window" ColorTop="Window" /> </RowStyleDefault> <GroupByRowStyleDefault BackColor="Control" BorderColor="Window"> </GroupByRowStyleDefault> <GroupByBox> <BoxStyle BackColor="ActiveBorder" BorderColor="Window"> </BoxStyle> </GroupByBox> <AddNewBox Hidden="False"> <BoxStyle BackColor="Window" BorderColor="InactiveCaption" BorderStyle="Solid" BorderWidth="1px"> <BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" WidthTop="1px" /> </BoxStyle> </AddNewBox> <ActivationObject BorderColor="" BorderWidth=""> </ActivationObject> <FilterOptionsDefault> <FilterDropDownStyle BackColor="White" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px" CustomRules="overflow:auto;" Font-Names="Verdana,Arial,Helvetica,sans-serif" Font-Size="11px" Height="300px" Width="200px"> <Padding Left="2px" /> </FilterDropDownStyle> <FilterHighlightRowStyle BackColor="#151C55" ForeColor="White"> </FilterHighlightRowStyle> <FilterOperandDropDownStyle BackColor="White" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px" CustomRules="overflow:auto;" Font-Names="Verdana,Arial,Helvetica,sans-serif" Font-Size="11px"> <Padding Left="2px" /> </FilterOperandDropDownStyle> </FilterOptionsDefault> </DisplayLayout> </igtbl:UltraWebGrid> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ZMConnectionString %>" DeleteCommand="DELETE FROM [UnitTypes] WHERE [UnitType] = @UnitType" InsertCommand="INSERT INTO [UnitTypes] ([UnitType]) VALUES (@UnitType)" SelectCommand="SELECT * FROM [UnitTypes]"> <DeleteParameters> <asp:Parameter Name="UnitType" Type="String" /> </DeleteParameters> <InsertParameters> <asp:Parameter Name="UnitType" Type="String" /> </InsertParameters> </asp:SqlDataSource> </form></body>
Hi,
Where's your update command and parameters in your sqldatasource?
Ed
Just my luck that the one version I post is faulty. How that happened I don't know because I did not manually change anything. Ok I corrected it and here is the updated section with all the entries. This time the wizard did not create the update statement so I entered that myself. Not relevant as the Insert didn't work even before I added the Update. I then used the designer to set the Insert statement and that is what is shown below.
This form is just one of 3 or 4 where I have tried to get this working I have checked the SQL statements in the other forms. They all look correct although the wizard does not always identify the PrimaryKey correctly.
Needless to say none of the versions did anything update/insert or delete. (BTW I added Row selectors too)
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ZMConnectionString %>" DeleteCommand="DELETE FROM [UnitTypes] WHERE [UnitType] = @UnitType" InsertCommand="INSERT INTO [UnitTypes] ([UnitType]) VALUES (@UnitType)" UpdateCommand="UPDATE [UnitTypes] SET [UnitType] = @UnitType WHERE [UnitType] = @original_UnitType" SelectCommand="SELECT [UnitType] FROM [UnitTypes]" OldValuesParameterFormatString="original_{0}"> <DeleteParameters> <asp:Parameter Name="UnitType" Type="String" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="UnitType" /> <asp:Parameter Name="original_UnitType" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="UnitType" Type="String"></asp:Parameter> <asp:Parameter Name="original_UnitType" Type="String"></asp:Parameter> </InsertParameters> </asp:SqlDataSource>
It is clearly to do with no postbacks of any kind happening. I can detect the Ajax postbacks when I sort the column but have yet to detect any kind of postback when data is changed.
How are you enabling the ajax? I don't see the browser and loadondemand set to xml. Are you using an updatepanel?
With an OLEDB connection (as opposed to System.Data.SqlClient which I before). The Delete now works. However Insert and Add do nothing and do not trigger the Inserting or Adding events, never mind the Inserted or Updated events.
<asp:SqlDataSource ID="DS1" runat="server" ConnectionString="<%$ ConnectionStrings:ZMOLEDBConnectionString %>" DeleteCommand="DELETE FROM [UnitTypes] WHERE [UnitType] = ?" InsertCommand="INSERT INTO [UnitTypes] ([UnitType]) VALUES (?)" SelectCommand="SELECT [UnitType] FROM [UnitTypes]" OldValuesParameterFormatString="original_{0}" ProviderName="<%$ ConnectionStrings:ZMOLEDBConnectionString.ProviderName %>"> <DeleteParameters> <asp:Parameter Name="original_UnitType" Type="String" /> </DeleteParameters> <InsertParameters> <asp:Parameter Name="UnitType" Type="String"></asp:Parameter> </InsertParameters> </asp:SqlDataSource>
I have handled the Datasource errors and set breakpoints when errors occur. It seems the SQL generated is not correct. On Update I get the error 'Could not find stored procedure', on Delete I get 'must declare variable @UnitType". On Add the Inserted event is not called, but I will work on that.
Again, tried all options in browser and loadondemand. My starting point was kb09994. I do (now) have a button to trigger a postback but still nothing happens. This is supposed to work without code?
Version with XML showing. I had tried this, honest.
<form id="form1" runat="server"> <div> </div> <igtbl:UltraWebGrid ID="UltraWebGrid1" runat="server" DataKeyField="UnitType" DataMember="DefaultView" DataSourceID="DS1" Height="200px" Width="325px" Browser="Xml"> <Bands> <igtbl:UltraGridBand DataKeyField="UnitType"> <AddNewRow View="NotSet" Visible="NotSet"> </AddNewRow> <Columns> <igtbl:UltraGridColumn BaseColumnName="UnitType" IsBound="True" Key="UnitType"> <Header Caption="UnitType"> </Header> </igtbl:UltraGridColumn> </Columns> </igtbl:UltraGridBand> </Bands> <DisplayLayout AllowAddNewDefault="Yes" AllowColSizingDefault="Free" AllowColumnMovingDefault="OnServer" AllowDeleteDefault="Yes" AllowSortingDefault="OnClient" AllowUpdateDefault="Yes" BorderCollapseDefault="Separate" HeaderClickActionDefault="SortMulti" Name="UltraWebGrid1" RowHeightDefault="20px" SelectTypeRowDefault="Extended" StationaryMargins="Header" StationaryMarginsOutlookGroupBy="True" TableLayout="Fixed" Version="4.00" ViewType="OutlookGroupBy" LoadOnDemand="Xml"> <FrameStyle BackColor="Window" BorderColor="InactiveCaption" BorderStyle="Solid" BorderWidth="1px" Font-Names="Microsoft Sans Serif" Font-Size="8.25pt" Height="200px" Width="325px"> </FrameStyle> <Pager MinimumPagesForDisplay="2"> <PagerStyle BackColor="LightGray" BorderStyle="Solid" BorderWidth="1px"> <BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" WidthTop="1px" /> </PagerStyle> </Pager> <EditCellStyleDefault BorderStyle="None" BorderWidth="0px"> </EditCellStyleDefault> <FooterStyleDefault BackColor="LightGray" BorderStyle="Solid" BorderWidth="1px"> <BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" WidthTop="1px" /> </FooterStyleDefault> <HeaderStyleDefault BackColor="LightGray" BorderStyle="Solid" HorizontalAlign="Left"> <BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" WidthTop="1px" /> </HeaderStyleDefault> <RowStyleDefault BackColor="Window" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px" Font-Names="Microsoft Sans Serif" Font-Size="8.25pt"> <Padding Left="3px" /> <BorderDetails ColorLeft="Window" ColorTop="Window" /> </RowStyleDefault> <GroupByRowStyleDefault BackColor="Control" BorderColor="Window"> </GroupByRowStyleDefault> <GroupByBox> <BoxStyle BackColor="ActiveBorder" BorderColor="Window"> </BoxStyle> </GroupByBox> <AddNewBox Hidden="False"> <BoxStyle BackColor="Window" BorderColor="InactiveCaption" BorderStyle="Solid" BorderWidth="1px"> <BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" WidthTop="1px" /> </BoxStyle> </AddNewBox> <ActivationObject BorderColor="" BorderWidth=""> </ActivationObject> <FilterOptionsDefault> <FilterDropDownStyle BackColor="White" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px" CustomRules="overflow:auto;" Font-Names="Verdana,Arial,Helvetica,sans-serif" Font-Size="11px" Height="300px" Width="200px"> <Padding Left="2px" /> </FilterDropDownStyle> <FilterHighlightRowStyle BackColor="#151C55" ForeColor="White"> </FilterHighlightRowStyle> <FilterOperandDropDownStyle BackColor="White" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px" CustomRules="overflow:auto;" Font-Names="Verdana,Arial,Helvetica,sans-serif" Font-Size="11px"> <Padding Left="2px" /> </FilterOperandDropDownStyle> </FilterOptionsDefault> </DisplayLayout> </igtbl:UltraWebGrid> <asp:SqlDataSource ID="DS1" runat="server" ConnectionString="<%$ ConnectionStrings:ZMConnectionString %>" DeleteCommand="DELETE FROM [UnitTypes] WHERE [UnitType] = @UnitType" InsertCommand="INSERT INTO [UnitTypes] ([UnitType]) VALUES (@UnitType)" UpdateCommand="UPDATE [UnitTypes] SET [UnitType] = @UnitType WHERE [UnitType] = @original_UnitType" SelectCommand="SELECT [UnitType] FROM [UnitTypes]" OldValuesParameterFormatString="original_{0}" UpdateCommandType="StoredProcedure"> <DeleteParameters> <asp:Parameter Name="UnitType" Type="String" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="UnitType" /> <asp:Parameter Name="original_UnitType" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="UnitType" Type="String"></asp:Parameter> <asp:Parameter Name="original_UnitType" Type="String"></asp:Parameter> </InsertParameters> </asp:SqlDataSource> </form>