M
Mike P
I must be missing something regarding update parameters. I have tried
using <asparameter> to specify my update parameters, and
<asp:ControlParameter> when <asparameter> didn't work for a particular
parameter. Here is my code :
<
asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="GetOppsTypeList" SelectCommandType="StoredProcedure"
UpdateCommand="UpdateOpportunity" UpdateCommandType="StoredProcedure">
<SelectParameters>
<asp:QueryStringParameter Name="CompanyKey"
QueryStringField="CompanyKey" Type="Int64" />
<asp:QueryStringParameter Name="OppsType" QueryStringField="OppsType"
Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asparameter Name="ProductTypeID" Type="Int32" />
<asparameter Name="OpportunityTypeID" Type="Int32" />
<asparameter Name="MonetaryValue" Type="Decimal" /> (first attempt)
(error : Cannot insert the value NULL into column 'MonetaryValue', table
'Canon.dbpportunity'; column does not allow nulls. UPDATE fails.The
statement has been terminated. )
<
asp:ControlParameter ControlID="txtValue" Name="MonetaryValue"
PropertyName="Text" /> (second attempt) (error : Could not find control
'txtValue' in ControlParameter 'MonetaryValue'.)
<asparameter Name="OpportunityID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<
asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"
DataKeyNames="OpportunityID" AllowSorting="True"
HeaderStyle-Height="24px"
AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="Product Type"
SortExpression="ProductType">
<ItemTemplate>
<asp:Label ID="lblProductType" Text='<%# Eval("ProductType") %>'
Runat="Server" />
</ItemTemplate>
<EditItemTemplate>
<aspropDownList ID="ddlProductType" runat="server"
DataSourceID="SqlDataSource2"
DataTextField="ProductType" DataValueField="ProductTypeID"
SelectedValue='<%# Bind("ProductTypeID") %>'></aspropDownList>
</EditItemTemplate>
<ControlStyle Width="80px" />
<ItemStyle Height="24px" Width="80px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Opportunity Type"
SortExpression="OpportunityType">
<ItemTemplate>
<asp:Label ID="lblOpportunityType" Text='<%# Eval("OpportunityType") %>'
Runat="Server" />
</ItemTemplate>
<EditItemTemplate>
<aspropDownList id="ddlOpportunityType" DataSourceID="SqlDataSource3"
Runat="Server"
DataTextField="OpportunityType" DataValueField="OpportunityTypeID"
SelectedValue='<%# Bind("OpportunityTypeID") %>'/>
</EditItemTemplate>
<ControlStyle Width="120px" />
<ItemStyle Height="24px" Width="120px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Value (£)"
SortExpression="MonetaryValue">
<ItemTemplate>
<asp:Label ID="lblValue" Text='<%# Eval("MonetaryValue") %>'
Runat="Server" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtValue" Text='<%# Eval("MonetaryValue") %>'
runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtValue" Display="None" ErrorMessage="Please enter a
Value" />
<asp:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="txtValue" Type="Double" MaximumValue="4000000"
MinimumValue="0" Display="None" ErrorMessage="Value must be numeric" />
</EditItemTemplate>
<ControlStyle Width="80px" />
<ItemStyle Height="24px" Width="80px" />
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" ButtonType="Image"
EditImageUrl="~/Images/btnEdit.jpg"
CancelImageUrl="~/Images/btnCancel.jpg"
UpdateImageUrl="~/Images/btnUpdate.jpg"/>
</Columns>
</asp:GridView>
Can anybody tell me what I am doing wrong here?
Cheers,
Mike
using <asparameter> to specify my update parameters, and
<asp:ControlParameter> when <asparameter> didn't work for a particular
parameter. Here is my code :
<
asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="GetOppsTypeList" SelectCommandType="StoredProcedure"
UpdateCommand="UpdateOpportunity" UpdateCommandType="StoredProcedure">
<SelectParameters>
<asp:QueryStringParameter Name="CompanyKey"
QueryStringField="CompanyKey" Type="Int64" />
<asp:QueryStringParameter Name="OppsType" QueryStringField="OppsType"
Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asparameter Name="ProductTypeID" Type="Int32" />
<asparameter Name="OpportunityTypeID" Type="Int32" />
<asparameter Name="MonetaryValue" Type="Decimal" /> (first attempt)
(error : Cannot insert the value NULL into column 'MonetaryValue', table
'Canon.dbpportunity'; column does not allow nulls. UPDATE fails.The
statement has been terminated. )
<
asp:ControlParameter ControlID="txtValue" Name="MonetaryValue"
PropertyName="Text" /> (second attempt) (error : Could not find control
'txtValue' in ControlParameter 'MonetaryValue'.)
<asparameter Name="OpportunityID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<
asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"
DataKeyNames="OpportunityID" AllowSorting="True"
HeaderStyle-Height="24px"
AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="Product Type"
SortExpression="ProductType">
<ItemTemplate>
<asp:Label ID="lblProductType" Text='<%# Eval("ProductType") %>'
Runat="Server" />
</ItemTemplate>
<EditItemTemplate>
<aspropDownList ID="ddlProductType" runat="server"
DataSourceID="SqlDataSource2"
DataTextField="ProductType" DataValueField="ProductTypeID"
SelectedValue='<%# Bind("ProductTypeID") %>'></aspropDownList>
</EditItemTemplate>
<ControlStyle Width="80px" />
<ItemStyle Height="24px" Width="80px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Opportunity Type"
SortExpression="OpportunityType">
<ItemTemplate>
<asp:Label ID="lblOpportunityType" Text='<%# Eval("OpportunityType") %>'
Runat="Server" />
</ItemTemplate>
<EditItemTemplate>
<aspropDownList id="ddlOpportunityType" DataSourceID="SqlDataSource3"
Runat="Server"
DataTextField="OpportunityType" DataValueField="OpportunityTypeID"
SelectedValue='<%# Bind("OpportunityTypeID") %>'/>
</EditItemTemplate>
<ControlStyle Width="120px" />
<ItemStyle Height="24px" Width="120px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Value (£)"
SortExpression="MonetaryValue">
<ItemTemplate>
<asp:Label ID="lblValue" Text='<%# Eval("MonetaryValue") %>'
Runat="Server" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtValue" Text='<%# Eval("MonetaryValue") %>'
runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtValue" Display="None" ErrorMessage="Please enter a
Value" />
<asp:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="txtValue" Type="Double" MaximumValue="4000000"
MinimumValue="0" Display="None" ErrorMessage="Value must be numeric" />
</EditItemTemplate>
<ControlStyle Width="80px" />
<ItemStyle Height="24px" Width="80px" />
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" ButtonType="Image"
EditImageUrl="~/Images/btnEdit.jpg"
CancelImageUrl="~/Images/btnCancel.jpg"
UpdateImageUrl="~/Images/btnUpdate.jpg"/>
</Columns>
</asp:GridView>
Can anybody tell me what I am doing wrong here?
Cheers,
Mike