Solved

ASp.net gridview Dropdown

Posted on 2011-09-29
3
454 Views
Last Modified: 2012-05-12
Hello I have been working on trying to use the updatecommand and insert command using SqlDataSource. I have a oracle back end.  I have attached the code for your review

Error message:

 ddCoverage' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value Dropdownlist-code.txt
<asp:GridView ID="_gwFinancial" runat="server" allowPaging="True" AllowSorting="True" 
                AutoGenerateColumns="False" HorizontalAlign="Center" CellSpacing="3" CellPadding="10" 
                  DataKeyNames="ACCOUNT_CODING_MATRIX_SK"    DataSourceID="OracleFinance"  CssClass="grid"
                EmptyDataText="There are no data records to display." 
                ForeColor="#333333" GridLines="None"  ShowFooter="true">
        
         <Columns>
          <asp:TemplateField HeaderText="Commands" ItemStyle-HorizontalAlign="Center"  ItemStyle-VerticalAlign="Middle">
                <ItemTemplate>
                    <asp:Button  Width="50px" runat="server" ID="Edit" Text="Edit" CommandName="Edit" />

                </ItemTemplate>

                <EditItemTemplate>
                    <asp:Button runat="server" Width="50px" ID="Update" Text="Update" CommandName="Update" />
                    <asp:Button runat="server" Width="75px" ID="Cancel" Text="Cancel" CommandName="Cancel" />
                </EditItemTemplate>

                <FooterTemplate>
                    <asp:Button runat="server" Width="75px" ID="Insert" Text="Insert" CommandName="Insert" />
                    <asp:Button runat="server" Width="75px" ID="Cancel" Text="Cancel" CommandName="Cancel" />
                </FooterTemplate>
            </asp:TemplateField>
            
            
            
            
                        <asp:TemplateField HeaderText="ACCOUNT_CODING_MATRIX_SK" 
                            SortExpression="ACCOUNT_CODING_MATRIX_SK" Visible="False">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox1" runat="server" 
                                    Text='<%# Bind("ACCOUNT_CODING_MATRIX_SK") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Bind("ACCOUNT_CODING_MATRIX_SK") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
            
            
            
            
            
            
            
            
            
            
                        <asp:TemplateField HeaderText="COVERAGE_TYPE" SortExpression="COVERAGE_TYPE">
                            <EditItemTemplate>
                                   <asp:DropDownList ID="ddCoverage" runat="server" 
                                     DataTextField="COVERAGE_TYPE" DataValueField="COVERAGE_TYPE"
                                     SelectedValue='<%# Bind("COVERAGE_TYPE") %>'>
                                    <asp:ListItem Text="PY" Value="Prior Year"/>
                                    <asp:ListItem Text="CY" Value="Current Year"/>
                                     <asp:ListItem Text="FP" Value="Future Period"/>
                                   </asp:DropDownList>
                                   
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label2" runat="server" Text='<%# Bind("COVERAGE_TYPE") %>'></asp:Label>
                            </ItemTemplate>
                            <HeaderStyle Width="80px" />
                            <ItemStyle HorizontalAlign="Center" />
                           <FooterTemplate>
                               <asp:DropDownList ID="ddCoverage" runat="server" 
                                     DataTextField="COVERAGE_TYPE" DataValueField="COVERAGE_TYPE"
                                     SelectedValue='<%# Bind("COVERAGE_TYPE") %>'>
                                    <asp:ListItem Text="PY" Value="Prior Year"/>
                                    <asp:ListItem Text="CY" Value="Current Year"/>
                                     <asp:ListItem Text="FP" Value="Future Period"/>
                                   </asp:DropDownList>
                            </FooterTemplate>
                          
                        </asp:TemplateField>
                        
            
            
            
            
            
         
        
        
        
        
        
        </Columns>
        
         <RowStyle BackColor="#E3EAEB" />
         <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
         <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
         <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
         <AlternatingRowStyle BackColor="White" />  
         
         
      
        </asp:GridView>
        
        
        <asp:SqlDataSource ID="OracleFinance" runat="server"  DataSourceMode="DataSet" EnableCaching="false"
                     ConnectionString="<%$ ConnectionStrings:OrcConn %>"
                      SelectCommand="SELECT ACCOUNT_CODING_MATRIX_SK,COVERAGE_TYPE FROM FDS.CFG_ACCOUNT_CODING_MATRIX" 
                            ProviderName="System.Data.OracleClient" InsertCommandType="Text"
                       InsertCommand="INSERT INTO [FDS.CFG_STAT_REPORT_DEFINITION] (STAT_RPT_ID, STAT_RPT_GRP,MTV_GROUP_TYPE,PRODUCT,BENEFIT_PACKAGE,EMPLOYEE_CNT_LOW,EMPLOYEE_CNT_HIGH) VALUES (:STAT_RPT_ID,:STAT_RPT_GRP, :MTV_GROUP_TYPE, :PRODUCT, :BENEFIT_PACKAGE, :EMPLOYEE_CNT_LOW, :EMPLOYEE_CNT_HIGH)" 
                        UpdateCommand="UPDATE FDS.CFG_ACCOUNT_CODING_MATRIX SET COVERAGE_TYPE =:COVERAGETYPE_ID  WHERE (ACCOUNT_CODING_MATRIX_SK = :ACCOUNT_CODING_MATRIX_SK)">
                         
                          <InsertParameters>
                               <asp:Parameter Name="COVERAGE_TYPE" Type="String" />
                              
                        </InsertParameters>
                        <UpdateParameters>
                                <asp:Parameter Name="COVERAGE_TYPE"   Type="String" /> 
                               
                        </UpdateParameters>
                      
               
                    </asp:SqlDataSource>

Open in new window

0
Comment
Question by:DevoinIT
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
jagssidurala earned 500 total points
ID: 36817187
this error will occured if you are assign a value to dropdown before binding datasource to it. check your code again
0
 
LVL 12

Expert Comment

by:jagssidurala
ID: 36817201
Selected values should be in the defined list.

i.e., Prior Year,  Current Year  OR Future Period


0
 

Author Closing Comment

by:DevoinIT
ID: 37457868
this worked fine
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now