Specifying UpdateParameters for ObjectDataSource bound to GridView

J

josef

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>
<asp:parameter Name="requestID" Type="Int32" / <asp:parameter Name="message" Type="String" />
</UpdateParameters>
</asp:ObjectDataSource>
 
J

josef

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top