Look at the SelectCommand of your SQLDataSource. You are not selecting the Priority_ID field in the select clause.
Main Topics
Browse All TopicsI get a DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'priority_id'. error message when I click the edit button on DataGrid. I am not quite sure what is going on. I am relatively new to this and followed the direction in my book but it still does not work. Below is my code. Any help would be appreciated.
<%@ Page Language="VB" MasterPageFile="~/masters/
<asp:Content ID="Content1" ContentPlaceHolderID="cphM
<h4>Add Sub-Priority Type...</h4>
<asp:formview id="frmAddSubPriority" runat="server" datakeynames="id" datasourceid="srcSubPriori
<edititemtemplate>
id:
<asp:label id="idLabel1" runat="server" text='<%# Eval("id") %>'></asp:label><br />
desc:
<asp:textbox id="descTextBox" runat="server" text='<%# Bind("desc") %>'>
</asp:textbox><br />
priority_id:
<asp:textbox id="priority_idTextBox" runat="server" text='<%# Bind("priority_id") %>'>
</asp:textbox><br />
weight:
<asp:textbox id="weightTextBox" runat="server" text='<%# Bind("weight") %>'>
</asp:textbox><br />
<asp:linkbutton id="UpdateButton" runat="server" causesvalidation="True" commandname="Update"
text="Update">
</asp:linkbutton>
<asp:linkbutton id="UpdateCancelButton" runat="server" causesvalidation="False" commandname="Cancel"
text="Cancel">
</asp:linkbutton>
</edititemtemplate>
<insertitemtemplate>
desc:
<asp:textbox id="descTextBox" runat="server" text='<%# Bind("desc") %>'></asp:textbox><br />
priority_id:
<asp:textbox id="priority_idTextBox" runat="server" text='<%# Bind("priority_id") %>'></asp:textbox><br />
weight:
<asp:textbox id="weightTextBox" runat="server" text='<%# Bind("weight") %>'></asp:textbox><br />
<asp:linkbutton id="InsertButton" runat="server" causesvalidation="True" commandname="Insert"
text="Insert"></asp:linkbu
<asp:linkbutton id="InsertCancelButton" runat="server" causesvalidation="False" commandname="Cancel"
text="Cancel"></asp:linkbu
</insertitemtemplate>
<itemtemplate>
id:
<asp:label id="idLabel" runat="server" text='<%# Eval("id") %>'></asp:label><br />
desc:
<asp:label id="descLabel" runat="server" text='<%# Bind("desc") %>'></asp:label><br />
priority_id:
<asp:label id="priority_idLabel" runat="server" text='<%# Bind("priority_id") %>'></asp:label><br />
weight:
<asp:label id="weightLabel" runat="server" text='<%# Bind("weight") %>'></asp:label><br />
<asp:linkbutton id="EditButton" runat="server" causesvalidation="False" commandname="Edit"
text="Edit"></asp:linkbutt
<asp:linkbutton id="DeleteButton" runat="server" causesvalidation="False" commandname="Delete"
text="Delete"></asp:linkbu
<asp:linkbutton id="NewButton" runat="server" causesvalidation="False" commandname="New"
text="New"></asp:linkbutto
</itemtemplate>
</asp:formview>
<h4>Current Sub-Priority Types...</h4>
<asp:gridview id="grdSubPriorities" runat="server" allowsorting="True" autogeneratecolumns="False
<columns>
<asp:commandfield showeditbutton="True" />
<asp:templatefield headertext="Description">
<itemtemplate><%# Eval("desc") %></itemtemplate>
<edititemtemplate>
<asp:textbox id="txtSubDesc" text='<%# Bind("desc") %>' runat="server"></asp:textb
</edititemtemplate>
</asp:templatefield>
<asp:templatefield headertext="Weighting">
<itemtemplate><%# Eval("weight") %></itemtemplate>
<edititemtemplate>
<asp:textbox id="txtDesc" text='<%# Bind("weight") %>' runat="server"></asp:textb
</edititemtemplate>
</asp:templatefield>
<asp:templatefield headertext="Priority">
<itemtemplate><%#Eval("pri
<edititemtemplate>
<asp:dropdownlist
id="ddlPriority"
datasourceid="srcPriority"
datatextfield="desc"
datavaluefield="id"
selectedvalue='<%#Bind("pr
runat="server">
</asp:dropdownlist>
</edititemtemplate>
</asp:templatefield>
</columns>
</asp:gridview>
<asp:sqldatasource id="srcSubPriority" runat="server" conflictdetection="Compare
insertcommand="INSERT INTO [sub_priority] ([desc], [priority_id], [weight]) VALUES (@desc, @priority_id, @weight)"
oldvaluesparameterformatst
selectcommand="SELECT sub_priority.id, sub_priority.[desc], sub_priority.weight,
priority.[desc] AS priority FROM sub_priority
JOIN priority ON sub_priority.priority_id = priority.id"
updatecommand="UPDATE [sub_priority] SET [desc] = @desc, [priority_id] = @priority_id,
[weight] = @weight WHERE [id] = @id">
<updateparameters>
<asp:parameter name="id" type="Int32" />
<asp:parameter name="desc" type="String" />
<asp:parameter name="priority_id" type="Int32" />
<asp:parameter name="weight" type="Byte" />
</updateparameters>
<insertparameters>
<asp:parameter name="desc" type="String" />
<asp:parameter name="priority_id" type="Int32" />
<asp:parameter name="weight" type="Byte" />
</insertparameters>
</asp:sqldatasource>
<asp:sqldatasource
id="srcPriority"
runat="server"
connectionstring="<%$ ConnectionStrings:conMaint
selectcommand="SELECT [id], [desc] FROM [priority]">
</asp:sqldatasource>
</asp:Content>
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
No. The DataValieField in the DropDownList was correct. It should be 'id' as that is the field in srcPriority's SelectCommand.
I would, however, change that select command slightly, to account for Null values.
<asp:sqldatasource
id="srcPriority"
runat="server"
connectionstring="<%$ ConnectionStrings:conMaint
SelectCommand="SELECT id, desc FROM priority union select Null, '-none-' order by 2">
</asp:sqldatasource>
The GridView may not be selecting because of such values, so I'd change it's datasource to use an outer join, just in case. It's worth a try. While editing that, also change the UpdateCommand to use the 'original_id' parameter.
<asp:sqldatasource id="srcSubPriority" runat="server"
CancelSelectOnNullParamete
ConflictDetection="Compare
ConnectionString="<%$ ConnectionStrings:conMaint
InsertCommand="INSERT INTO sub_priority ([desc], priority_id, weight) VALUES (@desc, @priority_id, @weight)"
OldValuesParameterFormatSt
SelectCommand="SELECT S.id, S.[desc], S.weight, S.priority_id, P.[desc] AS priority FROM sub_priority AS S LEFT OUTER JOIN priority AS P ON S.priority_id = P.id"
UpdateCommand="UPDATE sub_priority SET [desc] = @desc, priority_id = @priority_id, weight = @weight WHERE id = @original_id">
<updateparameters>
<asp:parameter name="original_id" type="Int32" />
<asp:parameter name="desc" type="String" />
<asp:parameter name="priority_id" type="Int32" />
<asp:parameter name="weight" type="Byte" />
</updateparameters>
<insertparameters>
<asp:parameter name="desc" type="String" />
<asp:parameter name="priority_id" type="Int32" />
<asp:parameter name="weight" type="Byte" />
</insertparameters>
</asp:sqldatasource>
Business Accounts
Answer for Membership
by: cezarFPosted on 2007-10-24 at 17:38:17ID: 20144073
inclucde priority_id in your selectcommand as follows:
SELECT sub_priority.priority_id sub_priority.id, sub_priority.[desc], sub_priority.weight, priority.[desc] AS priority FROM sub_priority
JOIN priority ON sub_priority.priority_id = priority.id