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

Problem with automatic insert item

1 Answer 104 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Hamza
Top achievements
Rank 1
Hamza asked on 18 Feb 2011, 11:49 AM
Hi all :)

when I make my RadGrid, I allow automatic insert items, and show it in the grid header, but it make no action in fact

here is my hole code


<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<div>
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
 
            <script type="text/javascript">
                function rowDblClick(sender, eventArgs) {
                    sender.get_masterTableView().editItem(eventArgs.get_itemIndexHierarchical());
                }
            </script>
 
        </telerik:RadCodeBlock>
        <telerik:RadAjaxManager runat="server" ID="RadAjaxManager1" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                        <telerik:AjaxUpdatedControl ControlID="RadWindowManager1" />
                        <telerik:AjaxUpdatedControl ControlID="RadInputManager1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1" />
            <telerik:RadAjaxPanel ID="RadAjaxPanel1"
    runat="server" LoadingPanelID="RadLoadingPanel1" Height="324px" Width="597px">
            <telerik:RadGrid ID="RadGrid1" runat="server"
    AutoGenerateColumns="False" GridLines="None"
                AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
                AllowAutomaticUpdates="True" AllowFilteringByColumn="True" AllowPaging="True"
                AllowSorting="True"
                DataSourceID="SqlDataSource1" ShowFooter="True" Skin="Black" Width="682px"
                PageSize="1">
                <MasterTableView DataKeyNames="History_ID" DataSourceID="SqlDataSource1" CommandItemDisplay="Top" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
                    <CommandItemSettings ExportToPdfText="Export to Pdf" />
                    <RowIndicatorColumn>
                        <HeaderStyle Width="20px" />
                    </RowIndicatorColumn>
                    <ExpandCollapseColumn>
                        <HeaderStyle Width="20px" />
                    </ExpandCollapseColumn>
                    <Columns>
                        <telerik:GridBoundColumn DataField="History_ID" DataType="System.Int32"
                            HeaderText="History_ID" ReadOnly="True" SortExpression="History_ID"
                            UniqueName="History_ID" Visible="False">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="User_ID" DataType="System.Int32"
                            HeaderText="User_ID" SortExpression="User_ID" UniqueName="User_ID"
                            Visible="False">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="DiesesInformation"
                            HeaderText="Disease Information" SortExpression="DiesesInformation"
                            UniqueName="DiesesInformation">
                        </telerik:GridBoundColumn>
                        <telerik:GridEditCommandColumn ButtonType="ImageButton" />
                        <telerik:GridButtonColumn ConfirmText="Delete this product?" ConfirmDialogType="RadWindow"
                        ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" />
                    </Columns>
                    <EditFormSettings>
                    <EditColumn ButtonType="ImageButton" />                   
                </EditFormSettings>
                </MasterTableView>
                <PagerStyle Mode="Slider" />
                <ClientSettings>
                <ClientEvents OnRowDblClick="rowDblClick" />
            </ClientSettings>
            </telerik:RadGrid>
            <telerik:RadInputManager runat="server" ID="RadInputManager1" Enabled="true">
            <telerik:TextBoxSetting BehaviorID="TextBoxSetting1">
            </telerik:TextBoxSetting>
            <telerik:NumericTextBoxSetting BehaviorID="NumericTextBoxSetting1" Type="Currency"
                AllowRounding="true" DecimalDigits="2">
            </telerik:NumericTextBoxSetting>
            <telerik:NumericTextBoxSetting BehaviorID="NumericTextBoxSetting2" Type="Number"
                AllowRounding="true" DecimalDigits="0" MinValue="0">
            </telerik:NumericTextBoxSetting>
        </telerik:RadInputManager>
        <telerik:RadWindowManager ID="RadWindowManager1" runat="server" />
            <asp:SqlDataSource ID="SqlDataSource1" runat="server"
            DeleteCommand="DELETE FROM [Ddisease_History] WHERE [History_ID] = @History_ID"
            InsertCommand="INSERT INTO [Ddisease_History] ([User_ID], [DiesesInformation]) VALUES (@User_ID, @DiesesInformation)"
            UpdateCommand="UPDATE [Ddisease_History] SET [User_ID] = @User_ID, [DiesesInformation] = @DiesesInformation WHERE [History_ID] = @History_ID">
            <DeleteParameters>
                <asp:Parameter Name="History_ID" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="User_ID" Type="Int32" />
                <asp:Parameter Name="DiesesInformation" Type="String" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="User_ID" Type="Int32" />
                <asp:Parameter Name="DiesesInformation" Type="String" />
                <asp:Parameter Name="History_ID" Type="Int32" />
            </UpdateParameters>
            </asp:SqlDataSource>
            </telerik:RadAjaxPanel>
        </div>

Here is only the code of Rad grid and my sqlDatasource


        <telerik:RadGrid ID="RadGrid1" runat="server"
AutoGenerateColumns="False" GridLines="None"
            AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
            AllowAutomaticUpdates="True" AllowFilteringByColumn="True" AllowPaging="True"
            AllowSorting="True"
            DataSourceID="SqlDataSource1" ShowFooter="True" Skin="Black" Width="682px"
            PageSize="1">
            <MasterTableView DataKeyNames="History_ID" DataSourceID="SqlDataSource1" CommandItemDisplay="Top" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
                <CommandItemSettings ExportToPdfText="Export to Pdf" />
                <RowIndicatorColumn>
                    <HeaderStyle Width="20px" />
                </RowIndicatorColumn>
                <ExpandCollapseColumn>
                    <HeaderStyle Width="20px" />
                </ExpandCollapseColumn>
                <Columns>
                    <telerik:GridBoundColumn DataField="History_ID" DataType="System.Int32"
                        HeaderText="History_ID" ReadOnly="True" SortExpression="History_ID"
                        UniqueName="History_ID" Visible="False">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="User_ID" DataType="System.Int32"
                        HeaderText="User_ID" SortExpression="User_ID" UniqueName="User_ID"
                        Visible="False">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="DiesesInformation"
                        HeaderText="Disease Information" SortExpression="DiesesInformation"
                        UniqueName="DiesesInformation">
                    </telerik:GridBoundColumn>
                    <telerik:GridEditCommandColumn ButtonType="ImageButton" />
                    <telerik:GridButtonColumn ConfirmText="Delete this product?" ConfirmDialogType="RadWindow"
                    ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" />
                </Columns>
                <EditFormSettings>
                <EditColumn ButtonType="ImageButton" />                   
            </EditFormSettings>
            </MasterTableView>
            <PagerStyle Mode="Slider" />
            <ClientSettings>
            <ClientEvents OnRowDblClick="rowDblClick" />
        </ClientSettings>
        </telerik:RadGrid>
 
 
 
 
 
 
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        DeleteCommand="DELETE FROM [Ddisease_History] WHERE [History_ID] = @History_ID"
        InsertCommand="INSERT INTO [Ddisease_History] ([User_ID], [DiesesInformation]) VALUES (@User_ID, @DiesesInformation)"
        UpdateCommand="UPDATE [Ddisease_History] SET [User_ID] = @User_ID, [DiesesInformation] = @DiesesInformation WHERE [History_ID] = @History_ID">
        <DeleteParameters>
            <asp:Parameter Name="History_ID" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="User_ID" Type="Int32" />
            <asp:Parameter Name="DiesesInformation" Type="String" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="User_ID" Type="Int32" />
            <asp:Parameter Name="DiesesInformation" Type="String" />
            <asp:Parameter Name="History_ID" Type="Int32" />
        </UpdateParameters>
        </asp:SqlDataSource>

my C# code:

using System;
using System.Collections;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Linq;
using Telerik.Web.UI;
 
public partial class R253H283HtlR1010L64_Lvu4evrR007e12_RwHaAnMza2832010_Pages_DeseaseHistory : System.Web.UI.UserControl
{
 
  
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlDataSource1.ConnectionString = ConnectionString.connectionString();
        SqlDataSource1.SelectCommand = "SELECT [DiesesInformation], [History_ID], [User_ID] FROM [Ddisease_History] WHERE [User_ID]=" + Session["UserInAdminPage"].ToString();
    }
 
}

1 Answer, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 23 Feb 2011, 01:01 PM
Hello Hamza,

I tested your code sample and the record is successfully inserted in the database however it is not shown in the grid because you have a restriction in the where clause of the select statement to show only records with certain User_ID equal to a session variable.

SqlDataSource1.SelectCommand = "SELECT [DiesesInformation], [History_ID], [User_ID] FROM [Ddisease_History] WHERE [User_ID]=" + Session["UserInAdminPage"].ToString();

This prevents the record from showing in the grid if it is with different User_ID than the specified. Furthermore you have set the PageSize=1 so only one record is shown per page and in case a record is entered with the same User_ID it will be shown on the next page in the grid.


Greetings,
Marin
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
Grid
Asked by
Hamza
Top achievements
Rank 1
Answers by
Marin
Telerik team
Share this question
or