specifying update parameters in gridview

M

Mike P

Where exactly are the updateparameters of a gridview picked up from? I
have created 2 very similar gridviews and given the updateparameters the
same names as in my edititemtemplates. Yet this method has worked for 1
gridview and failed for the second gridview. Here is my gridview :

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:XConnectionString
%>"
SelectCommand="ViewForecast"
SelectCommandType="StoredProcedure"
DeleteCommand="DeleteForecast"
DeleteCommandType="StoredProcedure"
UpdateCommand="UpdateForecast"
UpdateCommandType="StoredProcedure">
<DeleteParameters>
<asp:parameter Name="ForecastKey" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:parameter Name="ForecastKey" Type="Int32" />
<asp:parameter Name="CompanyKey" Type="Int64" />
<asp:parameter Name="ForecastType" Type="Char" />
<asp:parameter Name="MoneyValue" Type="Double" />
<asp:parameter Name="ForecastPercentage"
Type="Double" />
<asp:parameter Name="DueDate" Type="DateTime" />
<asp:parameter Name="UserKey" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>

<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$
ConnectionStrings:XConnectionString %>"
SelectCommand="GetCompaniesByUser"
SelectCommandType="StoredProcedure">
</asp:SqlDataSource>

<asp:SqlDataSource
ID="SqlDataSource3" runat="server"
ConnectionString="<%$
ConnectionStrings:XConnectionString %>"
SelectCommand="GetForecastTypes"
SelectCommandType="StoredProcedure">
</asp:SqlDataSource>

<asp:SqlDataSource
ID="SqlDataSource4" runat="server"
ConnectionString="<%$
ConnectionStrings:XConnectionString %>"

SelectCommand="GetForecastPercentages"
SelectCommandType="StoredProcedure">
</asp:SqlDataSource>

<asp:GridView ID="GridView1" runat="server"
DataSourceID="SqlDataSource1"
SkinID="Grey" AutoGenerateColumns="false"
DataKeyNames="ForecastKey" AllowSorting="true"
OnRowDataBound="GridView1_RowDataBound"
EditRowStyle-CssClass="dgedit" OnRowUpdated="GridView1_RowUpdated"
OnRowEditing="GridView1_RowEditing"
OnRowDeleting="GridView1_RowDeleting">
<Columns>
<asp:TemplateField HeaderText="Key"
SortExpression="ForecastKey">
<ItemTemplate>
<asp:Label
ID="lblForecastKey" Text='<%# Bind("ForecastKey") %>'
runat="server"></asp:Label>
</ItemTemplate>
<ItemStyle Height="24px"
Width="50px" />
</asp:TemplateField>

<asp:TemplateField HeaderText="Company"
SortExpression="CompanyName">
<ItemTemplate>
<asp:Label
ID="lblCompany" Text='<%# Eval("CompanyName") %>'
runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList
ID="ddlCompanyName" DataSourceID="SqlDataSource2" Runat="Server"

DataTextField="CompanyName" DataValueField="CompanyKey"
SelectedValue='<%# Bind("CompanyKey") %>' />
</EditItemTemplate>
<ItemStyle Height="24px"
Width="50px" />
</asp:TemplateField>

<asp:TemplateField
HeaderText="Forecast Type" SortExpression="ForecastDescription">
<ItemTemplate>
<asp:Label
ID="lblForecastType" Text='<%# Eval("ForecastDescription") %>'
runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList
ID="ddlForecastType" DataSourceID="SqlDataSource3" Runat="Server"

DataTextField="ForecastDescription" DataValueField="ForecastType"
SelectedValue='<%# Bind("ForecastType") %>' />
</EditItemTemplate>
<ItemStyle Height="24px"
Width="50px" />
</asp:TemplateField>

<asp:TemplateField
HeaderText="Value (£)" SortExpression="MoneyValue">
<ItemTemplate>
<asp:Label
ID="lblMoneyValue" Text='<%# Eval("MoneyValue", "{0:#,###.00}") %>'
runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox
ID="txtMoneyValue" Text='<%# Bind("MoneyValue", "{0:#,###.00}") %>'
runat="server"></asp:TextBox>

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"

ControlToValidate="txtMoneyValue" Display="None" ErrorMessage="Please
enter a Value" />
<asp:CompareValidator
ID="CompareValidator1" runat="server" Display="None"
ErrorMessage="Value must
be numeric" ControlToValidate="txtMoneyValue"
Type="Double"
Operator="DataTypeCheck"></asp:CompareValidator>
</EditItemTemplate>
<ItemStyle Height="24px"
Width="50px" />
</asp:TemplateField>

<asp:TemplateField
HeaderText="Probability (%)" SortExpression="ProbabilityValue">
<ItemTemplate>
<asp:Label
ID="lblProbability" Text='<%# Eval("ForecastPercentage") %>'
runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList
ID="ddlForecastPercentage" DataSourceID="SqlDataSource4" Runat="Server"

DataTextField="ForecastPercentageDescription"
DataValueField="ForecastPercentage" SelectedValue='<%#
Bind("ForecastPercentage") %>' />
</EditItemTemplate>
<ItemStyle Height="24px"
Width="50px" />
</asp:TemplateField>

<asp:TemplateField
HeaderText="Value (£) x Probability (%)"
SortExpression="ProbabilityValue">
<ItemTemplate>
<asp:Label
ID="lblProbabilityValue" Text='<%# Eval("ProbabilityValue",
"{0:#,###.00}") %>' runat="server"></asp:Label>
</ItemTemplate>
<ItemStyle Height="24px"
Width="50px" />
</asp:TemplateField>

<asp:TemplateField
HeaderText="Due Date" SortExpression="DueDate">
<ItemTemplate>
<asp:Label
ID="lblDueDate" Text='<%# Eval("DueDate", "{0:dd/MM/yyyy}") %>'
runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox
ID="txtDueDate" Text='<%# Bind("DueDate", "{0:dd/MM/yyyy}") %>'
runat="server"></asp:TextBox>
<!--or use this in SQL :
Select Convert(VarChar(10), GetDate(), 103)-->

<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"

ControlToValidate="txtDueDate" Display="None" ErrorMessage="Please enter
a Due Date" />
<asp:CompareValidator
ID="CompareValidator2" runat="server"
Display="None"
ErrorMessage="Please enter a valid Due Date in format dd/mm/yyyy"

ControlToValidate="txtDueDate" Type="Date"
Operator="DataTypeCheck"></asp:CompareValidator>
</EditItemTemplate>
<ItemStyle Height="24px"
Width="65px" />
</asp:TemplateField>

<asp:TemplateField
HeaderText="Last Edit Date" SortExpression="LastEditDate">
<ItemTemplate>
<asp:Label
ID="lblLastEditDate" Text='<%# Eval("LastEditDate", "{0:dd/MM/yyyy}")
%>' runat="server"></asp:Label>
</ItemTemplate>
<ItemStyle Height="24px"
Width="50px" />
</asp:TemplateField>

<asp:CommandField
ShowEditButton="True" ButtonType="Link" ShowCancelButton="True"
UpdateText="Update"
EditText="Edit" CancelText="Cancel" />

<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton
ID="DeleteButton"
CommandArgument='<%#
Eval("ForecastKey") %>'
CommandName="Delete"
runat="server">
Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

And here is my stored proc :

CREATE procedure dbo.UpdateForecast

(
@ForecastKey int,
@CompanyKey bigint,
@ForecastType char(1),
@MoneyValue float,
@ForecastPercentage float,
@DueDate datetime,
@UserKey int
)

as

update Forecast
set CompanySiteKey = @CompanyKey,
MoneyValue = @MoneyValue,
Probability = @ForecastPercentage,
ForecastType = @ForecastType,
InvoiceDate = @DueDate,
UserKey = @UserKey
where ForecastKey = @ForecastKey
GO

Can anybody with more experience of using gridview please tell me where
I am going wrong?


Cheers,

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top