Specifying UpdateParameters for ObjectDataSource bound to GridView

Discussion in 'ASP .Net' started by josef@wainz.net, Jul 11, 2007.

  1. Guest

    Can anyone tell me now to specify the Update Parameters for an
    ObjectDataSource bound to a GridView. From what I've read in the
    documentation, the Update Parameters are automatically derived from
    the DataSet bound to the GridView. This is a problem because I don't
    need to update fields like CreationDate and CreatedBy; therefore my
    methods don't have those parameters.

    I've looked at the Updating methods on both the GridView and
    ObjectDataSource without success.

    I've included a snippet below:

    <asp:GridView ID="gvMessage" Font-Size="Small"
    runat="server" ShowFooter="true" CellPadding="4" ForeColor="#333333"
    DataSourceID="odsMessage" DataKeyNames="MessageID"
    AutoGenerateColumns="False" CssClass="Message"
    OnRowCommand="gvMessage_RowCommand">
    <FooterStyle BackColor="#1C5E55" Font-Bold="True"
    ForeColor="White" />
    <RowStyle BackColor="#E3EAEB" />
    <EditRowStyle BackColor="#7C6F57" />
    <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" />
    <Columns>
    <asp:ButtonField
    HeaderText="   " >
    <ControlStyle Height="16px" Width="16px" /
    >

    <HeaderStyle Font-Size="XX-Small" />
    </asp:ButtonField>
    <asp:CommandField ButtonType="Image"
    ShowEditButton="True" EditImageUrl="./Images/edit.gif"
    CancelImageUrl="./Images/cancel.gif" UpdateImageUrl="./Images/
    save.gif" UpdateText="Save">
    <ControlStyle Height="16px" Width="16px" /
    >

    <HeaderStyle Font-Size="XX-Small" />
    </asp:CommandField>
    <asp:ButtonField HeaderText="Del"
    CommandName="Delete" Text="Delete" ButtonType="Image" ImageUrl="./
    Images/delete.gif" >
    <ControlStyle Height="16px" Width="16px" /
    >

    <HeaderStyle Font-Size="XX-Small" />
    </asp:ButtonField>
    <asp:TemplateField HeaderText="Add">
    <HeaderStyle Font-Size="XX-Small" />
    <FooterTemplate>
    <asp:ImageButton ID="ibAddMessage"
    runat="server" AlternateText="Add" CommandName="Add" Width="16px"
    Height="16px" ImageUrl="./Images/add.gif" />
    </FooterTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Message">
    <EditItemTemplate>
    <asp:TextBox ID="txtMessage"
    runat="server" Text='<%# Bind("Message") %>' TextMode="multiLine"
    Rows="5" Width="300"></asp:TextBox>
    </EditItemTemplate>
    <ItemTemplate>
    <asp:Label ID="lblMessage"
    runat="server" Text='<%# Bind("Message") %>' Width="300"></asp:Label>
    </ItemTemplate>
    <FooterTemplate>
    <asp:TextBox ID="txtMessageAdd"
    TextMode="multiLine" Rows="4" Width="300" runat="server"></
    asp:TextBox>
    </FooterTemplate>
    <ItemStyle Width="100px" />
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Created By">
    <ItemTemplate>
    <asp:Label ID="lblCreatedBy"
    runat="server" Text='<%# Bind("CreatedBy") %>'></asp:Label>
    </ItemTemplate>
    <ItemStyle Wrap="False" />
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Creation Date">
    <ItemTemplate>
    <asp:Label ID="lblCreationDate"
    runat="server" Text='<%# Bind("CreationDate") %>'></asp:Label>
    </ItemTemplate>
    <ItemStyle Wrap="False" />
    </asp:TemplateField>
    </Columns>
    </asp:GridView>

    <asp:ObjectDataSource ID="odsMessage" runat="server"
    TypeName="NobleIntl.CADRequest.BLL.Message"
    SelectMethod="GetByRequest" UpdateMethod="Update">
    <SelectParameters>
    <asp:SessionParameter DefaultValue="-1"
    Name="requestID" SessionField="RequestID"
    Type="Int32" />
    </SelectParameters>
    <UpdateParameters>
    <asp:parameter Name="MessageID" Type="Int32" /
    >

    <asp:parameter Name="requestID" Type="Int32" /
    >

    <asp:parameter Name="message" Type="String" />
    </UpdateParameters>
    </asp:ObjectDataSource>
     
    , Jul 11, 2007
    #1
    1. Advertising

  2. Guest

    On Jul 11, 4:57 pm, wrote:
    > Can anyone tell me now to specify the Update Parameters for an
    > ObjectDataSource bound to a GridView. From what I've read in the
    > documentation, the Update Parameters are automatically derived from
    > the DataSet bound to the GridView. This is a problem because I don't
    > need to update fields like CreationDate and CreatedBy; therefore my
    > methods don't have those parameters.
    >
    > I've looked at the Updating methods on both the GridView and
    > ObjectDataSource without success.
    >
    > I've included a snippet below:
    >
    > <asp:GridView ID="gvMessage" Font-Size="Small"
    > runat="server" ShowFooter="true" CellPadding="4" ForeColor="#333333"
    > DataSourceID="odsMessage" DataKeyNames="MessageID"
    > AutoGenerateColumns="False" CssClass="Message"
    > OnRowCommand="gvMessage_RowCommand">
    > <FooterStyle BackColor="#1C5E55" Font-Bold="True"
    > ForeColor="White" />
    > <RowStyle BackColor="#E3EAEB" />
    > <EditRowStyle BackColor="#7C6F57" />
    > <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" />
    > <Columns>
    > <asp:ButtonField
    > HeaderText="   " >
    > <ControlStyle Height="16px" Width="16px" /
    >
    > <HeaderStyle Font-Size="XX-Small" />
    > </asp:ButtonField>
    > <asp:CommandField ButtonType="Image"
    > ShowEditButton="True" EditImageUrl="./Images/edit.gif"
    > CancelImageUrl="./Images/cancel.gif" UpdateImageUrl="./Images/
    > save.gif" UpdateText="Save">
    > <ControlStyle Height="16px" Width="16px" /
    >
    > <HeaderStyle Font-Size="XX-Small" />
    > </asp:CommandField>
    > <asp:ButtonField HeaderText="Del"
    > CommandName="Delete" Text="Delete" ButtonType="Image" ImageUrl="./
    > Images/delete.gif" >
    > <ControlStyle Height="16px" Width="16px" /
    >
    > <HeaderStyle Font-Size="XX-Small" />
    > </asp:ButtonField>
    > <asp:TemplateField HeaderText="Add">
    > <HeaderStyle Font-Size="XX-Small" />
    > <FooterTemplate>
    > <asp:ImageButton ID="ibAddMessage"
    > runat="server" AlternateText="Add" CommandName="Add" Width="16px"
    > Height="16px" ImageUrl="./Images/add.gif" />
    > </FooterTemplate>
    > </asp:TemplateField>
    > <asp:TemplateField HeaderText="Message">
    > <EditItemTemplate>
    > <asp:TextBox ID="txtMessage"
    > runat="server" Text='<%# Bind("Message") %>' TextMode="multiLine"
    > Rows="5" Width="300"></asp:TextBox>
    > </EditItemTemplate>
    > <ItemTemplate>
    > <asp:Label ID="lblMessage"
    > runat="server" Text='<%# Bind("Message") %>' Width="300"></asp:Label>
    > </ItemTemplate>
    > <FooterTemplate>
    > <asp:TextBox ID="txtMessageAdd"
    > TextMode="multiLine" Rows="4" Width="300" runat="server"></
    > asp:TextBox>
    > </FooterTemplate>
    > <ItemStyle Width="100px" />
    > </asp:TemplateField>
    > <asp:TemplateField HeaderText="Created By">
    > <ItemTemplate>
    > <asp:Label ID="lblCreatedBy"
    > runat="server" Text='<%# Bind("CreatedBy") %>'></asp:Label>
    > </ItemTemplate>
    > <ItemStyle Wrap="False" />
    > </asp:TemplateField>
    > <asp:TemplateField HeaderText="Creation Date">
    > <ItemTemplate>
    > <asp:Label ID="lblCreationDate"
    > runat="server" Text='<%# Bind("CreationDate") %>'></asp:Label>
    > </ItemTemplate>
    > <ItemStyle Wrap="False" />
    > </asp:TemplateField>
    > </Columns>
    > </asp:GridView>
    >
    > <asp:ObjectDataSource ID="odsMessage" runat="server"
    > TypeName="NobleIntl.CADRequest.BLL.Message"
    > SelectMethod="GetByRequest" UpdateMethod="Update">
    > <SelectParameters>
    > <asp:SessionParameter DefaultValue="-1"
    > Name="requestID" SessionField="RequestID"
    > Type="Int32" />
    > </SelectParameters>
    > <UpdateParameters>
    > <asp:parameter Name="MessageID" Type="Int32" /
    >
    > <asp:parameter Name="requestID" Type="Int32" /
    >
    > <asp:parameter Name="message" Type="String" />
    > </UpdateParameters>
    > </asp:ObjectDataSource>


    It turns out that using Bind or Eval; such as: <asp:Label
    ID="lblCreationDate" runat="server" Text='<%# Bind("CreationDate")
    %>'></asp:Label> determines whether it is required as a parameter. Use
    Eval if you don't want the field to be an Update Parameter; use Bind
    if you do.
     
    , Jul 11, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Phillip Ian
    Replies:
    1
    Views:
    2,986
  2. Mike P

    GridView UpdateParameters

    Mike P, Apr 25, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    15,821
    =?Utf-8?B?Y2xpY2tvbg==?=
    Apr 25, 2006
  3. Max2006
    Replies:
    2
    Views:
    7,447
    Eliyahu Goldin
    Jul 10, 2007
  4. Replies:
    0
    Views:
    363
  5. Jeff
    Replies:
    0
    Views:
    529
Loading...

Share This Page