UpdateParameters?

Apr 17, 2007

Hello everyone,

 

I have a templatefield dropdownlist in a gridview. i'm trying to make the dropdownlist the controlID in updateparameters tag. But I get the following error when trying to update the datasource Thank you!. "Could not find control 'DropDownList3' in ControlParameter"

<asp:TemplateField HeaderText="IT Member" SortExpression="txtenteredby">

<EditItemTemplate>

<asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="ObjectDataSource1"

DataTextField="txtUserName">

</asp:DropDownList>

</EditItemTemplate>

<ItemTemplate>

<asp:Label ID="Label3" runat="server" Text='<%# Bind("txtenteredby") %>'></asp:Label>

</ItemTemplate>

</asp:TemplateField>

<asp:SqlDataSource

id="CustomersSqlDataSource"

runat="server"

ConnectionString="<%$ ConnectionStrings:SPIdb %>"

 

 

UpdateCommand="UPDATE table SET txtBName=@txtBName,txtPType=@txtType,txtBrand=@txtBrand,txtCondition=@txtCondition,txtstatus=@txtstatus,txtenteredby=@txtenteredby,txtDescription=@txtDescription where intID=@intID"

<UpdateParameters>

<asp:ControlParameter Name="txtenteredby" ControlId="DropDownList3" PropertyName="SelectedValue"/>

</UpdateParameters>

</asp:SqlDataSource>

 

 

View 6 Replies


ADVERTISEMENT

Specifying Updateparameters In Gridview

Jun 7, 2006

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 Forecastset CompanySiteKey = @CompanyKey,MoneyValue = @MoneyValue,Probability = @ForecastPercentage,ForecastType = @ForecastType,InvoiceDate = @DueDate,UserKey = @UserKeywhere ForecastKey = @ForecastKeyGO
Can anybody with more experience of using gridview please tell me where I am going wrong?
Cheers,
Mike

View 1 Replies View Related

Populate Automactly UpdateParameters

Jan 29, 2008

 Hi there!I'm trying to populate automactly a record in a table. I've tried this:   <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ProducaoLigacao %>" SelectCommand="UPDATE [Producao] SET [Prodas] = @Prodas WHERE ([ProdUserID] = @ProdUserID)">
<UpdateParameters>
<asp:Parameter DefaultValue="1" Name="ProdUserID" Type="Int32" />
<asp:Parameter DefaultValue="999" Name="Prodas" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource> Is this possible? Thanks in advance! 

View 5 Replies View Related

Programmatically Setting UpdateParameters

Feb 14, 2008

I am trying to customize my update statement and this MUST happen in codebehind, otherwise I will be overwriting data.  The following is updating the data that is should be.  The problem is that eventhough my UpdateCommand is clear in my .aspx and there are no parameters set... It is STILL running it's own update and overwriting the information it isn't supposed to.  From what I can tell, it is using a default.  What can I do to prevent this?
SqlDataSource1.UpdateCommand = "UPDATE MyTable SET MyField1=@MyField1 WHERE MyField2=@MyField2 AND MyField3=@MyField3"SqlDataSource1.UpdateParameters.Add("MyField1", "CustomText")
SqlDataSource1.UpdateParameters.Add("Task_ID", "Parameter")SqlDataSource1.UpdateParameters.Add("Comments", "Parameter")
SqlDataSource1.Update()
 

View 3 Replies View Related

Programmatically Setting UpdateParameters For A SQLDataSource Control

Sep 8, 2006

I need to provide defaults and sometimes overrides for items in SQLDataSource's UpdateParameters. I am attempting to do this in a FormView's ItemUpdating and ItemInserting events as follows: //========================================================================
// FormView1_ItemUpdating:
//========================================================================
protected void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e) {
// not sure if this is the bets place to put this or not?
dsDataSource.UpdateParameters["UpdatedTS"].DefaultValue = DateTime.Now.ToString();
dsDataSource.UpdateParameters["UpdatedUserID"].DefaultValue = ((csi.UserInfo)Session["UserInfo"]).QuotaUserID;
}
 In the example above I am attempting to set new values for the parameters which will replace the existing values. I have found that using the DefaultValue property works ONLY if there is no current value for the parameter.  Otherwise the values I specify are ingnored.The parameters of an ObjectDataSource provide a Value property but SQLDataSource parameters do not.How can I provide an override value without needing to place the value in the visible bound form element???If you can answer this you will be the FIRST person ever to answer one of my questions here!!!Thanks,Tony 

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved