By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,458 Members | 1,294 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,458 IT Pros & Developers. It's quick & easy.

specifying update parameters in gridview

P: n/a
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

*** Sent via Developersdex http://www.developersdex.com ***
Jun 7 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.