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

Problem with batchedit and insert command with defaultValue

3 Answers 27 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marc
Top achievements
Rank 1
Marc asked on 26 Oct 2016, 03:41 PM

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.....
        }
    }

3 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 31 Oct 2016, 11:39 AM
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.
0
Marc
Top achievements
Rank 1
answered on 02 Nov 2016, 11:10 AM

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.

0
Konstantin Dikov
Telerik team
answered on 07 Nov 2016, 08:56 AM
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.
Tags
Grid
Asked by
Marc
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Marc
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Share this question
or