Hello,
I have a form with Gridview and detailsview controls that connected to the same objectdatasource.
I use the gridview to list data from the datasource as well as let the user update data. I use the detailsview to let the user Insert new data.
I converted the field of the detailsview into a template field and in the 'Insert template" I inserted a Required field validation control
and set its properties to validate the right control.
When trying to Insert empty data into the detailsview control the validation control works fine, the problem starts when
the user edit a row in the gridview control and than click the Update, in this situation the validation control of the detailsview
doesn't let the update operation to take place in the gridview control.
any ideas?
The code is -
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="pk" DataSourceID="ObjectDataSource1" AllowPaging="True" PageSize="5">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="teacher" HeaderText="teacher"
SortExpression="teacher" Visible="False" />
<asp:BoundField DataField="school" HeaderText="Class"
SortExpression="school" >
<ItemStyle Width="200px" />
</asp:BoundField>
<asp:BoundField DataField="pk" HeaderText="pk" InsertVisible="False"
ReadOnly="True" SortExpression="pk" Visible="False" />
</Columns>
</asp:GridView>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataKeyNames="pk" DataSourceID="ObjectDataSource1" DefaultMode="Insert"
Height="50px" Width="221px">
<Fields>
<asp:BoundField DataField="teacher" HeaderText="teacher"
SortExpression="teacher" Visible="False" />
<asp:TemplateField HeaderText="school" SortExpression="school">
<InsertItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("school") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox2" ErrorMessage="*">*</asp:RequiredFieldValidator>
</InsertItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="pk" HeaderText="pk" InsertVisible="False"
ReadOnly="True" SortExpression="pk" />
<asp:CommandField ShowInsertButton="True" />
</Fields>
</asp:DetailsView>