I have a GridView that functions off an sqlDataSource, it allows inserting and updating data. However, after the data is inserted, the "UpdatedBY" should not be editable by the user. So I added a readonly property to that bound column and set it to true, which generates the following error upon attempting to edit/update a column: Must declare the scalar variable "@UpdateBY". Note: the error only occurs when I implement a readonly property onto the "UpdateBY" column. When removed, no error when updating the Grid, but I do not want the user to be able to modify the UpdateBY column
Hypertext:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="Mode_ID" DataSourceID="SqlDataSource1"
AutoGenerateEditButton="True" AllowPaging="True" AllowSorting="True">
<Columns>
<asp:BoundField DataField="Mode_ID" HeaderText="Mode ID" SortExpression="Mode_ID" Visible="false" />
<asp:BoundField DataField="ShipMode" HeaderText="Ship Mode" SortExpression="ShipMode" />
<asp:TemplateField HeaderText="Active" SortExpression="Active">
<EditItemTemplate>
<asp:CheckBox ID="chkactive" runat="server" Checked='<%# Bind("Active") %>'></asp:CheckBox>
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("Active") %>'></asp:CheckBox>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UpdateDate" HeaderText="Update Date" SortExpression="UpdateDate" />
<asp:BoundField DataField="UpdateBY" HeaderText="Update BY" SortExpression="UpdateBY" ReadOnly="true" />
</Columns>
</asp:GridView>
...the SQL data source:
<asp:SqlDataSource
ID="SqlDataSource1"
ConnectionString="<%$ ConnectionStrings:ShipperNotificationConnectionString %>"
SelectCommand="SELECT Mode_ID, ShipMode, Active, UpdateDate, UpdateBY FROM [ShipMode]"
UpdateCommand="UPDATE ShipMode SET ShipMode=@ShipMode,
Active=@Active,UpdateDate=@UpdateDate, UpdateBY=@UpdateBY
WHERE Mode_ID=@Mode_ID"
InsertCommand="INSERT ShipMode (ShipMode,Active,UpdateDate,UpdateBY)
VALUES (@ShipMode,@Active,@UpdateDate,@UpdateBY)"
runat="server"
/>
could I get some assistance as to what I'm missing / failing to understand please?