Master-Details with GridView and FormView and Paging

T

ThePurpleCat

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.Product"
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.Product">
</asp:ObjectDataSource>
</asp:Content>
 

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

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top