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

Radgrid, insert, not showing all fields and not saving to dabase

5 Answers 144 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Felice
Top achievements
Rank 1
Felice asked on 25 Aug 2013, 03:09 PM
Hi, I am just starting using Telerik. So, first of all  sorry if I make basic questions. I have been trough video, tutorial and documentation but I am not coming right.
I have a RadGrid with 5 fields. When I click on "add new record", the grid open-up but only 3 of the 5 fields are shown.
The two fields not showing are:
- the CustomerID, which is an  auto-increase identity. I do not need this field to show up because I expect the database to manage it, so this is not the problem;
-the other one is the CustomerName, which is the primary key of the table, this is important to be shown and filled in.
 I do not understand why these two fields do not show, however, how can I make the CustomerName showing up?

Moreover, when I click on "Insert", nothing happen. Is this related to the fact that there are missing fields in the table? Or do I need additional code to post the new records to the database?
Here is the RadGrid code:

    <telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" CellSpacing="0" Culture="it-IT" DataSourceID="SqlDataSource1" GridLines="None">
<MasterTableView AutoGenerateColumns="False" CommandItemDisplay="TopAndBottom" DataKeyNames="CustomerName" DataSourceID="SqlDataSource1">
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
 
<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
 
<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
 
    <Columns>
        <telerik:GridBoundColumn DataField="CustomerID" DataType="System.Int32" FilterControlAltText="Filter CustomerID column" HeaderText="CustomerID" ReadOnly="True" SortExpression="CustomerID" UniqueName="CustomerID">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="CustomerName" FilterControlAltText="Filter CustomerName column" HeaderText="CustomerName" ReadOnly="True" SortExpression="CustomerName" UniqueName="CustomerName">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="CustomerContact" FilterControlAltText="Filter CustomerContact column" HeaderText="CustomerContact" SortExpression="CustomerContact" UniqueName="CustomerContact">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="Country" FilterControlAltText="Filter Country column" HeaderText="Country" SortExpression="Country" UniqueName="Country">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="date" DataType="System.DateTime" FilterControlAltText="Filter date column" HeaderText="date" SortExpression="date" UniqueName="date">
        </telerik:GridBoundColumn>
    </Columns>
 
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
</MasterTableView>
 
<FilterMenu EnableImageSprites="False"></FilterMenu>
</telerik:RadGrid>
Some help will be appreciated. Thanks.

5 Answers, 1 is accepted

Sort by
0
Felice
Top achievements
Rank 1
answered on 25 Aug 2013, 09:09 PM
Actually I solved the problem but the solution is scaring me. The field not showing up in add new record was set to "read only" = false.
I manullay changed it to read only, save solution, close, close vs, start all over again, build the solution and then set the filed to "read only" false. Now it works!!!
obviously the insert did not work because the field is mandatory and was showing null.

I am still battling to get update and delete warking. They are also set to true. I am wondering if the problem is similar!
0
Accepted
Princy
Top achievements
Rank 2
answered on 26 Aug 2013, 03:42 AM
Hi Felice,

When you set a column as ReadOnly="true",it is not available for editing or insertion.As the name suggests,it is only kept to be ReadOnly,which can be seen in the view mode.If you want edit and insert to perform for those column,please set ReadOnly="false".

Thanks,
Princy
0
Matt
Top achievements
Rank 1
answered on 01 Dec 2017, 08:34 PM

I have the same problem and hacking it by convincing the mark up that readonly is actually false didn't work. For example,

<telerik:GridTemplateColumn DataField="Title" HeaderText="Title" SortExpression="Title" UniqueName="Title"  HeaderStyle-Width="250px">

                    <ItemTemplate>
                        <%# Eval("Title") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadTextBox ID="RTB_Title" runat="server" CssClass="label" Width="250px" MaxLength="100"/>
                        <asp:RequiredFieldValidator ID="RFV_Title" runat="server" ControlToValidate="RTB_Title" Text="&#8666;" ForeColor="#E31932" Font-Bold="true" Font-Size="14pt" Display="Dynamic" SetFocusOnError="true" />
                        <asp:RegularExpressionValidator ID="REV_Title" runat="server" ControlToValidate="RTB_Title" Text="&#8666;" ForeColor="#E31932" Font-Bold="true" Font-Size="14pt" Display="Dynamic" SetFocusOnError="true" ValidationExpression="^[ A-Za-z0-9_'-]*$"/>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>

and look at the screen shot. It's not set to read only and yet when I attempt to insert a record, the text box doesn't appear.

This is bound via SQLDataSource. I have other grids and they don't do this. What happened?

And please don't tell me that it works fine in your sandbox.

0
Matt
Top achievements
Rank 1
answered on 01 Dec 2017, 08:38 PM

I had the same problem. I was using multiple row editing but needed to add:

<BatchEditingSettings EditType="Row" />

Mazel Tov

0
Matt
Top achievements
Rank 1
answered on 01 Dec 2017, 08:52 PM
Sorry for the double post. I received a 500 error and didn't think the post went through.
Tags
Grid
Asked by
Felice
Top achievements
Rank 1
Answers by
Felice
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Matt
Top achievements
Rank 1
Share this question
or