471,581 Members | 2,475 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,581 software developers and data experts.

Master-Details with GridView and FormView and Paging

Hi, I'm a newbie to ASP.NET programming but not to Visual Studio.

I'm having trouble getting my Master-Details page to work. I have a
page enabled GridView which is linked to a FormView control through an
objectdatasource. The paging on my GridView works fine except that when
I change the page the FormView
does not update. I tried setting the selectedindex to 0 in the
GridView's PageIndexChanged event and manually binding the formview but
the selectedvalue that the function sees is the old value from
the page being changed from and not the new page so the FormView
refreshes with the wrong value. I also bind the formview on pageload
but that doesn't work either. What am I doing wrong? Here's my
code-behind, followed by the form script...

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

If Not IsNothing(Me.gvwProducts.SelectedValue) Then
Me.fvwCurrentProduct.DataBind()
End If

End Sub

Protected Sub gvwProducts_PageIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
gvwProducts.PageIndexChanged
Me.gvwProducts.SelectedIndex = 0
fvwCurrentProduct.DataBind()
End Sub

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master"
AutoEventWireup="false" CodeFile="ViewProducts.aspx.vb"
Inherits="MichaelBaker.JobTracker.UI.ViewProducts" title="Untitled
Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
&nbsp; &nbsp;
<asp:FormView ID="fvwCurrentProduct" runat="server"
DataSourceID="odsCurrentProduct">
<EditItemTemplate>
FileType:
<asp:TextBox ID="FileTypeTextBox" runat="server" Text='<%#
Bind("FileType") %>'>
</asp:TextBox><BR />
AssignedTo:
<asp:TextBox ID="AssignedToTextBox" runat="server"
Text='<%# Bind("AssignedTo") %>'>
</asp:TextBox><BR />
Status:
<asp:TextBox ID="StatusTextBox" runat="server" Text='<%#
Bind("Status") %>'>
</asp:TextBox><BR />
MediaPath:
<asp:TextBox ID="MediaPathTextBox" runat="server" Text='<%#
Bind("MediaPath") %>'>
</asp:TextBox><BR />
JobId:
<asp:TextBox ID="JobIdTextBox" runat="server" Text='<%#
Bind("JobId") %>'>
</asp:TextBox><BR />
ProductStatusId:
<asp:TextBox ID="ProductStatusIdTextBox" runat="server"
Text='<%# Bind("ProductStatusId") %>'>
</asp:TextBox><BR />
ID:
<asp:TextBox ID="IDTextBox" runat="server" Text='<%#
Bind("ID") %>'>
</asp:TextBox><BR />
AttachDate:
<asp:TextBox ID="AttachDateTextBox" runat="server"
Text='<%# Bind("AttachDate") %>'>
</asp:TextBox><BR />
Description:
<asp:TextBox ID="DescriptionTextBox" runat="server"
Text='<%# Bind("Description") %>'>
</asp:TextBox><BR />
User:
<asp:TextBox ID="UserTextBox" runat="server" Text='<%#
Bind("User") %>'>
</asp:TextBox><BR />
<asp:LinkButton ID="UpdateButton" runat="server"
CausesValidation="True" CommandName="Update"
Text="Update">
</asp:LinkButton>
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</EditItemTemplate>
<InsertItemTemplate>
FileType:
<asp:TextBox ID="FileTypeTextBox" runat="server" Text='<%#
Bind("FileType") %>'>
</asp:TextBox><BR />
AssignedTo:
<asp:TextBox ID="AssignedToTextBox" runat="server"
Text='<%# Bind("AssignedTo") %>'>
</asp:TextBox><BR />
Status:
<asp:TextBox ID="StatusTextBox" runat="server" Text='<%#
Bind("Status") %>'>
</asp:TextBox><BR />
MediaPath:
<asp:TextBox ID="MediaPathTextBox" runat="server" Text='<%#
Bind("MediaPath") %>'>
</asp:TextBox><BR />
JobId:
<asp:TextBox ID="JobIdTextBox" runat="server" Text='<%#
Bind("JobId") %>'>
</asp:TextBox><BR />
ProductStatusId:
<asp:TextBox ID="ProductStatusIdTextBox" runat="server"
Text='<%# Bind("ProductStatusId") %>'>
</asp:TextBox><BR />
ID:
<asp:TextBox ID="IDTextBox" runat="server" Text='<%#
Bind("ID") %>'>
</asp:TextBox><BR />
AttachDate:
<asp:TextBox ID="AttachDateTextBox" runat="server"
Text='<%# Bind("AttachDate") %>'>
</asp:TextBox><BR />
Description:
<asp:TextBox ID="DescriptionTextBox" runat="server"
Text='<%# Bind("Description") %>'>
</asp:TextBox><BR />
User:
<asp:TextBox ID="UserTextBox" runat="server" Text='<%#
Bind("User") %>'>
</asp:TextBox><BR />
<asp:LinkButton ID="InsertButton" runat="server"
CausesValidation="True" CommandName="Insert"
Text="Insert">
</asp:LinkButton>
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</InsertItemTemplate>
<ItemTemplate>
FileType:
<asp:Label ID="FileTypeLabel" runat="server" Text='<%#
Bind("FileType") %>'></asp:Label><BR />
AssignedTo:
<asp:Label ID="AssignedToLabel" runat="server" Text='<%#
Bind("AssignedTo") %>'>
</asp:Label><BR />
Status:
<asp:Label ID="StatusLabel" runat="server" Text='<%#
Bind("Status") %>'></asp:Label><BR />
MediaPath:
<asp:Label ID="MediaPathLabel" runat="server" Text='<%#
Bind("MediaPath") %>'></asp:Label><BR />
JobId:
<asp:Label ID="JobIdLabel" runat="server" Text='<%#
Bind("JobId") %>'></asp:Label><BR />
ProductStatusId:
<asp:Label ID="ProductStatusIdLabel" runat="server"
Text='<%# Bind("ProductStatusId") %>'>
</asp:Label><BR />
ID:
<asp:Label ID="IDLabel" runat="server" Text='<%# Bind("ID")
%>'></asp:Label><BR />
AttachDate:
<asp:Label ID="AttachDateLabel" runat="server" Text='<%#
Bind("AttachDate") %>'>
</asp:Label><BR />
Description:
<asp:Label ID="DescriptionLabel" runat="server" Text='<%#
Bind("Description") %>'>
</asp:Label><BR />
User:
<asp:Label ID="UserLabel" runat="server" Text='<%#
Bind("User") %>'></asp:Label><BR />
</ItemTemplate>
</asp:FormView>
<asp:ObjectDataSource ID="odsCurrentProduct" runat="server"
SelectMethod="GetProductById"
TypeName="MichaelBaker.JobTracker.BLL.Products.Pro duct"
UpdateMethod="UpdateProduct">
<UpdateParameters>
<asp:Parameter Name="ProductId" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="gvwProducts"
Name="ProductId" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:GridView ID="gvwProducts" runat="server"
AutoGenerateColumns="False" DataSourceID="odsProducts"
AllowPaging="True" DataKeyNames="ID" SelectedIndex="0">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="ID" HeaderText="Product Id"
ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="FileType" HeaderText="File Type"
SortExpression="FileType" />
<asp:BoundField DataField="AssignedTo" HeaderText="Assigned
To" SortExpression="AssignedTo" />
<asp:BoundField DataField="Status" HeaderText="Status"
SortExpression="Status" />
<asp:BoundField DataField="MediaPath" HeaderText="Media
Path" SortExpression="MediaPath" />
<asp:BoundField DataField="JobId" HeaderText="Job Id"
SortExpression="JobId" />
<asp:BoundField DataField="AttachDate" HeaderText="Attach
Date" SortExpression="AttachDate" />
<asp:BoundField DataField="Description"
HeaderText="Description" SortExpression="Description" />
<asp:BoundField DataField="User" HeaderText="User"
ReadOnly="True" SortExpression="User" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="odsProducts" runat="server"
SelectMethod="GetProducts"
TypeName="MichaelBaker.JobTracker.BLL.Products.Pro duct">
</asp:ObjectDataSource>
</asp:Content>

Oct 18 '06 #1
0 4610

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Michael Herman \(Parallelspace\) | last post: by
4 posts views Thread by Steve Franks | last post: by
2 posts views Thread by Jon Spivey | last post: by
17 posts views Thread by Rob R. Ainscough | last post: by
7 posts views Thread by Just Me | last post: by
6 posts views Thread by =?Utf-8?B?SmF5IFBvbmR5?= | last post: by
5 posts views Thread by =?Utf-8?B?bXVzb3NkZXY=?= | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.