开发者

objectDataSource binding with ASP.NET gridview auto adding parameters

开发者 https://www.devze.com 2022-12-20 03:38 出处:网络
I have a gridview databound to an objectdatasource. Everything worked great until I changed 2 columns from asp:BoundField to asp:TemplateField. These are the UPC column and the Part column. I wanted t

I have a gridview databound to an objectdatasource. Everything worked great until I changed 2 columns from asp:BoundField to asp:TemplateField. These are the UPC column and the Part column. I wanted to show a link button for each of these fields that take the user to another page. Now asp.net expects these two fields to be parameters on the update store procedure. Why is this? How do I get it to not assume these columns need to be passed to the store procedure?

Here is the code for the grid view:

          <asp:GridView ID="GridView1" runat="server" SkinID="MSDefau开发者_开发知识库lt" AutoGenerateColumns="False" DataSourceID="CartDataSource" PageSize="25"
              Width="100%" DataKeyNames="CartId" EmptyDataText="The cart is empty" OnRowDataBound="GridView1_RowDataBound" onrowcommand="GridView1_RowCommand">
              <Columns>
                  <asp:CommandField ShowDeleteButton="True" ShowEditButton="True">
                      <ItemStyle Width="8%" />
                  </asp:CommandField>
                  <asp:BoundField DataField="CartId" HeaderText="CartId" InsertVisible="False" ReadOnly="True"
                      SortExpression="CartId" Visible="False" />
                  <asp:TemplateField HeaderText="UPC" SortExpression="UPC">
                      <ItemTemplate>
                          <asp:LinkButton ID="LinkButton1" runat="server" CommandName="ShowInfo" CommandArgument='<%# Bind("UPC") %>' Text='<%# Bind("UPC") %>'></asp:LinkButton>
                      </ItemTemplate>
                      <ItemStyle Width="9%" />
                  </asp:TemplateField>
                  <asp:BoundField DataField="Mfr" HeaderText="Mfr" ReadOnly="True" SortExpression="Mfr">
                      <ItemStyle Width="11%" />
                  </asp:BoundField>
                  <asp:TemplateField HeaderText="Part" SortExpression="Part">
                      <ItemTemplate>
                          <asp:LinkButton ID="LinkButton2" runat="server" CommandName="ShowInfo" CommandArgument='<%# Bind("UPC") %>' Text='<%# Bind("Part") %>'></asp:LinkButton>
                      </ItemTemplate>
                      <ItemStyle Width="10%" />
                  </asp:TemplateField>
                  <asp:BoundField DataField="CustPart" HeaderText="Cust Part" ReadOnly="True" SortExpression="CustPart">
                      <ItemStyle Width="10%" />
                  </asp:BoundField>
                  <asp:BoundField DataField="PartDesc" HeaderText="Description" ReadOnly="True" SortExpression="PartDesc">
                      <ItemStyle Width="30%" Wrap="True" />
                  </asp:BoundField>
                  <asp:TemplateField HeaderText="Marked" SortExpression="Marked">
                      <EditItemTemplate>
                          <asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("Marked") %>' />
                      </EditItemTemplate>
                      <ItemTemplate>
                          <asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("Marked") %>' Enabled="false" />
                      </ItemTemplate>
                      <ItemStyle Width="2%" />
                  </asp:TemplateField>
                  <asp:BoundField DataField="Quantity" DataFormatString="{0:d}" HeaderText="Quantity"
                      SortExpression="Quantity">
                      <ItemStyle HorizontalAlign="Right" Width="4%" />
                  </asp:BoundField>
                  <asp:TemplateField HeaderText="Price" SortExpression="Price">
                      <ItemStyle HorizontalAlign="Right" Width="8%" />
                      <ItemTemplate>
                          <asp:Label ID="lblPrice" runat="server"></asp:Label>
                          <asp:LinkButton ID="LnkBtnCallLocalBranch" runat="server" Visible="false" PostBackUrl="~/UserProfile/LocalDistributors.aspx">call local branch</asp:LinkButton>
                      </ItemTemplate>
                  </asp:TemplateField>
                  <asp:TemplateField HeaderText="Ext Price" SortExpression="ExtPrice">
                      <ItemStyle HorizontalAlign="Right" Width="8%" />
                      <ItemTemplate>
                          <asp:Label ID="lblExtPrice" runat="server"></asp:Label>
                      </ItemTemplate>
                  </asp:TemplateField>
              </Columns>
          </asp:GridView>

Here is the objectDataSource code

<asp:ObjectDataSource ID="CartDataSource" runat="server" OldValuesParameterFormatString="{0}" DeleteMethod="DeleteWithKey" SelectMethod="GetDataByCUserId"
    TypeName="PunchoutData.CartDataSetTableAdapters.CartTableAdapter" UpdateMethod="UpdateQuantityAndMarked" OnUpdated="CartDataSource_Updated" OnObjectCreated="CartDataSource_ObjectCreated">
    <DeleteParameters>
        <asp:Parameter Name="cartid" Type="Int32" />
    </DeleteParameters>
    <UpdateParameters>
        <asp:Parameter Name="marked" Type="Boolean" />
        <asp:Parameter Name="quantity" Type="Int32" />
        <asp:Parameter Name="cartid" Type="Int32" />
    </UpdateParameters>
    <SelectParameters>
        <asp:SessionParameter Name="cuserid" SessionField="CUserId" Type="Int32" />
    </SelectParameters>
</asp:ObjectDataSource>

Here is the error that is being generated

ObjectDataSource 'CartDataSource' could not find a non-generic method 'UpdateQuantityAndMarked' that has parameters: Marked, Quantity, CartId, UPC, Part.


The issue was that I was using <%# Bind("UPC") %> and I should have been using <%# Eval("UPC") %>. Bind is two-way and Eval is one-way(read-only)

0

精彩评论

暂无评论...
验证码 换一张
取 消