Problem with batchedit and insert command with defaultValue

4 posts, 0 answers
  1. Marc
    Marc avatar
    8 posts
    Member since:
    Aug 2016

    Posted 26 Oct Link to this post

    I have a radgrid in batchedit. The Update and Select works fine but Insert didn't.

    I use a defaultValue for a Select and Insert in code behind. For a select this works fine but when i try to insert the field of Database have null v

    <telerik:RadGrid  ID="RGV" runat="server" Width="500px"
                                    RenderMode="Lightweight" GridLines="None" 
                                    AllowAutomaticDeletes="True"
                                    AllowAutomaticInserts="True"
                                    PageSize="10"
                                    AllowAutomaticUpdates="True"
                                    AllowPaging="True"
                                    AutoGenerateColumns="False"
                                    DataSourceID="SDS"
                                    Skin="WebBlue" >
                    <MasterTableView CommandItemDisplay="TopAndBottom" DataKeyNames="id"
                        DataSourceID="SDS" HorizontalAlign="NotSet" EditMode="Batch" AutoGenerateColumns="False"
                        CommandItemSettings-AddNewRecordText="Insertar centro"
                        CommandItemSettings-SaveChangesText="Guardar"
                        CommandItemSettings-CancelChangesText="Cancelar"
                        CommandItemSettings-RefreshText="Refrescar"
                        NoMasterRecordsText="No data"
                        NoDetailRecordsText="No data">
                        <BatchEditingSettings EditType="Cell" />
                        <Columns>
                            <telerik:GridBoundColumn DataField="Empresa"
                                HeaderText="Empresa"
                                SortExpression="Empresa"
                                UniqueName="Empresa">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Numero"
                                HeaderText="Numero"
                                SortExpression="Numero"
                                UniqueName="Numero">
                            </telerik:GridBoundColumn>
                            <telerik:GridDateTimeColumn DataField="Desde"
                                HeaderText="Desde"
                                SortExpression="Desde"
                                UniqueName="Desde" >
                            </telerik:GridDateTimeColumn>
                            <telerik:GridDateTimeColumn DataField="HastaEl"
                                HeaderText="Hasta el"
                                SortExpression="HastaEl"
                                UniqueName="HastaEl" >
                            </telerik:GridDateTimeColumn>
                        </Columns>
                    </MasterTableView>
                    <ClientSettings AllowKeyboardNavigation="true"></ClientSettings>
                </telerik:RadGrid>
     
            <asp:SqlDataSource ID="SDS" runat="server" ConnectionString="<%$ ConnectionStrings:PCMConnectionString %>"
                SelectCommand="SELECT * From Table1 Where idRevisionCentros=@idRevisionCentros"
                InsertCommand="INSERT INTO Table1 (idRevisionCentros,Empresa,Numero,Desde,HastaEl) VALUES (@idRevisionCentros,@Empresa,@Numero,@Desde,@HastaEl)"
                UpdateCommand="UPDATE Table1 SET Empresa=@Empresa, Numero=@Numero,Desde=@Desde,HastaEl=@HastaEl WHERE id = @id">
                <SelectParameters>
                    <asp:parameter Name="idRevisionCentros" type="Int32" />
                </SelectParameters>
                <InsertParameters>
                    <asp:parameter Name="idRevisionCentros" type="Int32" />
                    <asp:Parameter Name="Empresa" Type="String"></asp:Parameter>
                    <asp:Parameter Name="Numero" Type="Int32"></asp:Parameter>
                    <asp:Parameter Name="Desde" Type="DateTime"></asp:Parameter>
                    <asp:Parameter Name="HastaEl" Type="DateTime"></asp:Parameter>
                </InsertParameters>
                <UpdateParameters>
                    <asp:Parameter Name="id" Type="Int32"></asp:Parameter>
                    <asp:Parameter Name="Empresa" Type="String"></asp:Parameter>
                    <asp:Parameter Name="Numero" Type="Int32"></asp:Parameter>
                    <asp:Parameter Name="Desde" Type="DateTime"></asp:Parameter>
                    <asp:Parameter Name="HastaEl" Type="DateTime"></asp:Parameter>
                </UpdateParameters>
            </asp:SqlDataSource>
        </fieldset>
    protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
    int idRevisionCentros = getIdRevisionCentros();//return any number, for exemple 1;
                        SDS.SelectParameters[0].DefaultValue = idRevisionCentros.ToString();//<-- Works fine
                        SDS.InsertParameters[0].DefaultValue = idRevisionCentros.ToString();//<-- Insert null in DB for this field.....
            }
        }
  2. Kostadin
    Admin
    Kostadin avatar
    1711 posts

    Posted 31 Oct Link to this post

    Hi Marc,

    Could you please try setting the default value declarative in the InsertParameters and let me know about the result? Another option of setting a default value when inserting a new item is to use the DefaultInsertValue property of the column. Please check out the following code snippet.
    <telerik:GridBoundColumn
       DataField="Area"
       HeaderText="Area"
       DefaultInsertValue="24" />

    Regards,
    Kostadin
    Telerik by Progress
    Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Marc
    Marc avatar
    8 posts
    Member since:
    Aug 2016

    Posted 02 Nov in reply to Kostadin Link to this post

    I cant declare DefaultInsertValue in asp.net code because depending of querystring I take one or other value.

    I need a grid equal to a 1 to N database table. This is cause I need put a ForaingKey value in <asp:parameter Name="idRevisionCentros" type="Int32" /> and I was put in page load but when im going to add a new register the idRevisionCentros (ForaingKey) are NULL.

  5. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1800 posts

    Posted 07 Nov Link to this post

    Hi Marc,

    Can you please try to remove the !IsPostBack condition and apply the parameter on each postback:
    protected void Page_Load(object sender, EventArgs e)
        {
            int idRevisionCentros = getIdRevisionCentros();//return any number, for exemple 1;
                    SDS.SelectParameters[0].DefaultValue = idRevisionCentros.ToString();
                    SDS.InsertParameters[0].DefaultValue = idRevisionCentros.ToString();
        }

    Hope this helps.


    Regards,
    Konstantin Dikov
    Telerik by Progress
    Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
Back to Top