Solved

ASp.net gridview Dropdown

Posted on 2011-09-29
3
462 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

822 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