Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Specifying UpdateParameters for ObjectDataSource bound to GridView

Reply
Thread Tools

Specifying UpdateParameters for ObjectDataSource bound to GridView

 
 
josef@wainz.net
Guest
Posts: n/a
 
      07-11-2007
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>
<asparameter Name="MessageID" Type="Int32" /
>

<asparameter Name="requestID" Type="Int32" /
>

<asparameter Name="message" Type="String" />
</UpdateParameters>
</asp:ObjectDataSource>

 
Reply With Quote
 
 
 
 
josef@wainz.net
Guest
Posts: n/a
 
      07-11-2007
On Jul 11, 4:57 pm, (E-Mail Removed) 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>
> <asparameter Name="MessageID" Type="Int32" /
>
> <asparameter Name="requestID" Type="Int32" /
>
> <asparameter 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble with UpdateParameters and GridView Jeff ASP .Net 0 10-21-2008 08:19 AM
Updating a GridView bound to ObjectDataSource andrewbb@gmail.com ASP .Net 0 08-09-2007 12:39 AM
GridView bound to ObjectDataSource: How to refresh the Data? Max2006 ASP .Net 2 07-10-2007 07:20 AM
ObjectDataSource: UpdateParameters ignored when specifying DataObjectTypeName? Phillip Ian ASP .Net 1 04-28-2006 03:25 PM
GridView UpdateParameters Mike P ASP .Net 3 04-25-2006 03:42 PM



Advertisments