Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6040639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:32:37+00:00 2026-05-23T06:32:37+00:00

Ok guys, so I read this: How to set SelectedValue of DropDownList in GridView

  • 0

Ok guys, so I read this:
How to set SelectedValue of DropDownList in GridView EditTemplate

and I’m having the same issue. However, I don’t want to bind the selected value to the displayed text, but instead the values. They are different attributes selected from a SQLDataSource. Here is my DDL code with its SQLDataSource:

<asp:DropDownList ID="FoodCodeDropDownList" runat="server"
     DataSourceID="Plant_Carton_Food_List"
     DataTextField="Food_Description"
     DataValueField="PlantMaterial_FoodID"
     SelectedValue='<%# Bind("PlantMaterial_FoodID") %>' >
</asp:DropDownList>
<asp:SqlDataSource ID="Plant_Carton_Food_List" runat="server" 
     ConnectionString="<%$ ConnectionStrings:OMSConnectionString %>" 
     SelectCommand="SELECT   P.PlantMaterial_FoodID,
               M.Material_SAP_Value + ' - ' + MD.SAP_Long_Description AS Food_Description 
          FROM Plant_Carton_Food AS P 
          LEFT OUTER JOIN Material_Descriptions AS MD 
               ON P.PlantMaterial_FoodID = MD.Material_ID 
          LEFT OUTER JOIN Materials AS M 
               ON P.PlantMaterial_FoodID = M.Material_ID">
 </asp:SqlDataSource>

Here is the (abridged) SQLDataSource of the GridView:

   <asp:SqlDataSource ID="Plant_Carton_Table" runat="server" 
        OldValuesParameterFormatString="old_{0}"
        ConnectionString="<%$ ConnectionStrings:DBConnectionString %>" 
        OnInserting="Plant_Carton_Food_Table_Inserting"
        OnInserted="Plant_Carton_Food_Table_Inserted"
        InsertCommand="spPlantCartonInsert" InsertCommandType="StoredProcedure" 
        SelectCommand="spPlantCartonSelect" SelectCommandType="StoredProcedure" 
        UpdateCommand="spPlantCartonUpdate" UpdateCommandType="StoredProcedure">
        <UpdateParameters>
            <asp:Parameter Name="Active_Case"           Type="Boolean" />
            <asp:Parameter Name="PlantMaterial_FoodID"  Type="String" />
            <asp:Parameter Name="PlantMaterial_CaseID"  Type="String" />
            ...
        </UpdateParameters>
        ...
    </asp:SqlDataSource>

And, finally, my exception:

DataBinding: ‘System.Data.DataRowView’
does not contain a property with the
name ‘PlantMaterial_FoodID’.

I really don’t have much knowledge on how databinding through the GridView Edit templates work, but I was able to see that the correct values pass through the OnRowCommand event handler for updates. How do I propagate these values to the SQLDataSource without getting NULL?

Right now, I guess any explanation on how databinding with GridView templates work in general would be beneficial as well. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:32:38+00:00Added an answer on May 23, 2026 at 6:32 am

    This isn’t really an answer to the question, but instead a workaround… but it works for me.

    I added PlantMaterial_FoodID as a hidden column into the GridView and changed the SelectedValue binding on the DropDownList to reference this new column, as shown below.

    New Column

    <asp:TemplateField HeaderText="Food ID" SortExpression="Food_ID">
        <EditItemTemplate>
            <asp:Label ID="FoodIDLabel" runat="server" Text='<%# Eval("Food_ID") %>'</asp:Label>
        </EditItemTemplate>
        <ItemTemplate>
            <asp:Label ID="FoodIDLabel" runat="server" Text='<%# Bind("Food_ID") %>'</asp:Label>
        </ItemTemplate>
    </asp:TemplateField>
    

    …and here is the new binding

    <asp:DropDownList ID="FoodCodeDropDownList" runat="server"
        DataSourceID="Plant_Carton_Food_List" DataTextField="Food_Description"
        DataValueField="PlantMaterial_FoodID" SelectedValue='<%# Bind("Food_ID") %>'
    </asp:DropDownList>
    

    This effectively sets the selected dropdownlist index to the correct value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys im having a problem trying to program out a set of logic.
I've read dozens of posts on this topic, but everyone else is having horizontal
Okay guys, I have read through all the other posts and question on jQuery
Could you guys give me an example how to read and write from/to xml
I've read Romain Guy's post on the <merge /> tag, but I still don't
guys am having some troubles with running out of memory when displaying an animation
Guys, I've came across this problem I can't resolve myselg, I'm pretty sure I
Ok guys, i've search in google and here in stackoverflow for this answer and
Hey guys, I'm writing a script to update status log, this involves frequently file
I use this to read a widestring out of the cmd (Windows Shell). var

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.