Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

Specifying UpdateParameters for ObjectDataSource bound to GridView

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
josef@wainz.net - 11 Jul 2007 21:57 GMT
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="&#160;&#160;&#160;" >
                           <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>
josef@wainz.net - 11 Jul 2007 21:59 GMT
On Jul 11, 4:57 pm, j...@wainz.net 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
[quoted text clipped - 104 lines]
>                     </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.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.