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
objectdatasourc e. 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 PageIndexChange d 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.EventArg s) Handles Me.Load
If Not IsNothing(Me.gv wProducts.Selec tedValue) Then
Me.fvwCurrentPr oduct.DataBind( )
End If
End Sub
Protected Sub gvwProducts_Pag eIndexChanged(B yVal sender As
Object, ByVal e As System.EventArg s) Handles
gvwProducts.Pag eIndexChanged
Me.gvwProducts. SelectedIndex = 0
fvwCurrentProdu ct.DataBind()
End Sub
<%@ Page Language="VB" MasterPageFile= "~/MasterPage.mast er"
AutoEventWireup ="false" CodeFile="ViewP roducts.aspx.vb "
Inherits="Micha elBaker.JobTrac ker.UI.ViewProd ucts" title="Untitled
Page" %>
<asp:Content ID="Content1" ContentPlaceHol derID="ContentP laceHolder1"
Runat="Server">
<asp:FormView ID="fvwCurrentP roduct" runat="server"
DataSourceID="o dsCurrentProduc t">
<EditItemTempla te>
FileType:
<asp:TextBox ID="FileTypeTex tBox" runat="server" Text='<%#
Bind("FileType" ) %>'>
</asp:TextBox><BR />
AssignedTo:
<asp:TextBox ID="AssignedToT extBox" runat="server"
Text='<%# Bind("AssignedT o") %>'>
</asp:TextBox><BR />
Status:
<asp:TextBox ID="StatusTextB ox" runat="server" Text='<%#
Bind("Status") %>'>
</asp:TextBox><BR />
MediaPath:
<asp:TextBox ID="MediaPathTe xtBox" runat="server" Text='<%#
Bind("MediaPath ") %>'>
</asp:TextBox><BR />
JobId:
<asp:TextBox ID="JobIdTextBo x" runat="server" Text='<%#
Bind("JobId") %>'>
</asp:TextBox><BR />
ProductStatusId :
<asp:TextBox ID="ProductStat usIdTextBox" runat="server"
Text='<%# Bind("ProductSt atusId") %>'>
</asp:TextBox><BR />
ID:
<asp:TextBox ID="IDTextBox" runat="server" Text='<%#
Bind("ID") %>'>
</asp:TextBox><BR />
AttachDate:
<asp:TextBox ID="AttachDateT extBox" runat="server"
Text='<%# Bind("AttachDat e") %>'>
</asp:TextBox><BR />
Description:
<asp:TextBox ID="Description TextBox" runat="server"
Text='<%# Bind("Descripti on") %>'>
</asp:TextBox><BR />
User:
<asp:TextBox ID="UserTextBox " runat="server" Text='<%#
Bind("User") %>'>
</asp:TextBox><BR />
<asp:LinkButt on ID="UpdateButto n" runat="server"
CausesValidatio n="True" CommandName="Up date"
Text="Update">
</asp:LinkButton>
<asp:LinkButt on ID="UpdateCance lButton" runat="server"
CausesValidatio n="False" CommandName="Ca ncel"
Text="Cancel">
</asp:LinkButton>
</EditItemTemplat e>
<InsertItemTemp late>
FileType:
<asp:TextBox ID="FileTypeTex tBox" runat="server" Text='<%#
Bind("FileType" ) %>'>
</asp:TextBox><BR />
AssignedTo:
<asp:TextBox ID="AssignedToT extBox" runat="server"
Text='<%# Bind("AssignedT o") %>'>
</asp:TextBox><BR />
Status:
<asp:TextBox ID="StatusTextB ox" runat="server" Text='<%#
Bind("Status") %>'>
</asp:TextBox><BR />
MediaPath:
<asp:TextBox ID="MediaPathTe xtBox" runat="server" Text='<%#
Bind("MediaPath ") %>'>
</asp:TextBox><BR />
JobId:
<asp:TextBox ID="JobIdTextBo x" runat="server" Text='<%#
Bind("JobId") %>'>
</asp:TextBox><BR />
ProductStatusId :
<asp:TextBox ID="ProductStat usIdTextBox" runat="server"
Text='<%# Bind("ProductSt atusId") %>'>
</asp:TextBox><BR />
ID:
<asp:TextBox ID="IDTextBox" runat="server" Text='<%#
Bind("ID") %>'>
</asp:TextBox><BR />
AttachDate:
<asp:TextBox ID="AttachDateT extBox" runat="server"
Text='<%# Bind("AttachDat e") %>'>
</asp:TextBox><BR />
Description:
<asp:TextBox ID="Description TextBox" runat="server"
Text='<%# Bind("Descripti on") %>'>
</asp:TextBox><BR />
User:
<asp:TextBox ID="UserTextBox " runat="server" Text='<%#
Bind("User") %>'>
</asp:TextBox><BR />
<asp:LinkButt on ID="InsertButto n" runat="server"
CausesValidatio n="True" CommandName="In sert"
Text="Insert">
</asp:LinkButton>
<asp:LinkButt on ID="InsertCance lButton" runat="server"
CausesValidatio n="False" CommandName="Ca ncel"
Text="Cancel">
</asp:LinkButton>
</InsertItemTempl ate>
<ItemTemplate >
FileType:
<asp:Label ID="FileTypeLab el" runat="server" Text='<%#
Bind("FileType" ) %>'></asp:Label><BR />
AssignedTo:
<asp:Label ID="AssignedToL abel" runat="server" Text='<%#
Bind("AssignedT o") %>'>
</asp:Label><BR />
Status:
<asp:Label ID="StatusLabel " runat="server" Text='<%#
Bind("Status") %>'></asp:Label><BR />
MediaPath:
<asp:Label ID="MediaPathLa bel" 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="ProductStat usIdLabel" runat="server"
Text='<%# Bind("ProductSt atusId") %>'>
</asp:Label><BR />
ID:
<asp:Label ID="IDLabel" runat="server" Text='<%# Bind("ID")
%>'></asp:Label><BR />
AttachDate:
<asp:Label ID="AttachDateL abel" runat="server" Text='<%#
Bind("AttachDat e") %>'>
</asp:Label><BR />
Description:
<asp:Label ID="Description Label" runat="server" Text='<%#
Bind("Descripti on") %>'>
</asp:Label><BR />
User:
<asp:Label ID="UserLabel" runat="server" Text='<%#
Bind("User") %>'></asp:Label><BR />
</ItemTemplate>
</asp:FormView>
<asp:ObjectData Source ID="odsCurrentP roduct" runat="server"
SelectMethod="G etProductById"
TypeName="Micha elBaker.JobTrac ker.BLL.Product s.Product"
UpdateMethod="U pdateProduct">
<UpdateParamete rs>
<asp:Paramete r Name="ProductId " Type="Int32" />
</UpdateParameter s>
<SelectParamete rs>
<asp:ControlPar ameter ControlID="gvwP roducts"
Name="ProductId " PropertyName="S electedValue"
Type="Int32" />
</SelectParameter s>
</asp:ObjectDataS ource>
<asp:GridView ID="gvwProducts " runat="server"
AutoGenerateCol umns="False" DataSourceID="o dsProducts"
AllowPaging="Tr ue" DataKeyNames="I D" SelectedIndex=" 0">
<Columns>
<asp:CommandFie ld ShowSelectButto n="True" />
<asp:BoundFie ld DataField="ID" HeaderText="Pro duct Id"
ReadOnly="True" SortExpression= "ID" />
<asp:BoundFie ld DataField="File Type" HeaderText="Fil e Type"
SortExpression= "FileType" />
<asp:BoundFie ld DataField="Assi gnedTo" HeaderText="Ass igned
To" SortExpression= "AssignedTo " />
<asp:BoundFie ld DataField="Stat us" HeaderText="Sta tus"
SortExpression= "Status" />
<asp:BoundFie ld DataField="Medi aPath" HeaderText="Med ia
Path" SortExpression= "MediaPath" />
<asp:BoundFie ld DataField="JobI d" HeaderText="Job Id"
SortExpression= "JobId" />
<asp:BoundFie ld DataField="Atta chDate" HeaderText="Att ach
Date" SortExpression= "AttachDate " />
<asp:BoundFie ld DataField="Desc ription"
HeaderText="Des cription" SortExpression= "Descriptio n" />
<asp:BoundFie ld DataField="User " HeaderText="Use r"
ReadOnly="True" SortExpression= "User" />
</Columns>
</asp:GridView>
<asp:ObjectData Source ID="odsProducts " runat="server"
SelectMethod="G etProducts"
TypeName="Micha elBaker.JobTrac ker.BLL.Product s.Product">
</asp:ObjectDataS ource>
</asp:Content>