Integration of GridView and FormView

G

gary7584

Hello,

I have set up a master-detail relationship with a GridView and FormView that
is working well, with the ability to select a record in the GridView and then
update or delete that record in the FormView, or insert a new record. The
problem I’m having is after I make a modification to my table in the
FormView, I can’t get my GridView to display the changes that have been made.
It seems like a simple binding or refresh command would take care of this,
but I've come up empty so far.

Here is my code. Thanks in advance for your help.

Gary

<html>
<head id="Head1" runat="server" />
<body>
<form id="Form1" runat="server">

<asp:SqlDataSource runat="server" ID="MySource"
ConnectionString="SERVER=ResearchDB1;DATABASE=sqlbpa1"
DataSourceMode="DataSet"
SelectCommand="SELECT pageid, pagetypeid, pagetemplateid, pagename
FROM page"
UpdateCommand="UPDATE page SET pagetypeid=@pagetypeid,
pagetemplateid=@pagetemplateid, pagename=@pagename WHERE pageid=@pageid"
InsertCommand="INSERT INTO page VALUES (@pageid, @pagetypeid,
@pagetemplateid, @pagename)"
DeleteCommand="DELETE FROM page WHERE pageid=@pageid">
</asp:SqlDataSource>

<asp:SqlDataSource runat="server" ID="MyDetailSource"
ConnectionString="SERVER=ResearchDB1;DATABASE=sqlbpa1"
DataSourceMode="DataSet"
SelectCommand="SELECT pageid, pagetypeid, pagetemplateid, pagename
FROM page"
UpdateCommand="UPDATE page SET pagetypeid=@pagetypeid,
pagetemplateid=@pagetemplateid, pagename=@pagename WHERE pageid=@pageid"
InsertCommand="INSERT INTO page VALUES (@pageid, @pagetypeid,
@pagetemplateid, @pagename)"
DeleteCommand="DELETE FROM page WHERE pageid=@pageid"
FilterExpression="pageid='{0}'">
<filterparameters>
<asp:ControlParameter Name="PageID" ControlID="grid"
PropertyName="SelectedValue" />
</filterparameters>
</asp:SqlDataSource>

<asp:GridView runat="server" ID="grid"
DataSourceId="MySource"
pagesize="4"
allowpaging="true"
autogenerateselectbutton="true"
AutoGenerateColumns="false"
DataKeyNames="PageID">
<columns>
<asp:boundfield datafield="PageID" headertext="PageID" />
<asp:boundfield datafield="PageTypeID"
headertext="PageTypeID" />
<asp:boundfield datafield="PageTemplateID"
headertext="PageTemplateID" />
<asp:boundfield datafield="PageName" headertext="PageName" />
</columns>
</asp:GridView>

<asp:FormView ID="FormView1" runat="server"
DataSourceID="MyDetailSource" DataKeyNames="PageID">
<ItemTemplate>
<table>
<tr>
<td>
<p>PageID</p>
</td>
<td>
<%#Eval("PageID")%>
</td>
</tr>
<tr>
<tr>
<td>
<p>PageTypeID</p>
</td>
<td>
<%#Eval("PageTypeID")%>
</td>
</tr>
<tr>
<tr>
<td>
<p>PageTemplateID</p>
</td>
<td>
<%#Eval("PageTemplateID")%>
</td>
</tr>
<tr>
<td>
<p>PageName</p>
</td>
<td>
<%#Eval("PageName")%>
</td>
</tr>
<tr>
<td colspan = "2">
<asp:Button ID="Edit" Text="Edit" CommandName="Edit"
runat="server" />
<asp:Button ID="New" Text="New..." CommandName="New"
runat="server" />
<asp:Button ID="Delete" Text="Delete..."
CommandName="Delete" runat="server" />
</td>
</tr>
</table>
</ItemTemplate>
<EditItemTemplate>
<table>
<tr>
<td>
<p>PageID</p>
</td>
<td>
<%#Eval("PageID")%>
</td>
</tr>
<tr>
<tr>
<td>
<p>PageTypeID</p>
</td>
<td>
<asp:TextBox runat=server ID="PageTypeID" Text='<%#
Bind("PageTypeID") %>' />
</td>
</tr>
<tr>
<tr>
<td>
<p>PageTemplateID</p>
</td>
<td>
<asp:TextBox runat=server ID="PageTemplateID" Text='<%#
Bind("PageTemplateID") %>' />
</td>
</tr>
<tr>
<td>
<p>PageName</p>
</td>
<td>
<asp:TextBox Width=500 runat=server ID="PageName" Text='<%#
Bind("pagename") %>' />
</td>
</tr>
<tr>
<td colspan = "2">
<asp:Button ID="UpdateButton" Text="Update"
CommandName="Update" runat="server" />
<asp:Button ID="CancelButton" Text="Cancel"
CommandName="Cancel" runat="server" />
</td>
</tr>
</table>
</EditItemTemplate>
<InsertItemTemplate>
<table>
<tr>
<td>
<p>PageID</p>
</td>
<td>
<asp:TextBox runat=server ID="PageID" Text='<%#
Bind("PageID") %>' />
</td>
</tr>
<tr>
<tr>
<td>
<p>PageTypeID</p>
</td>
<td>
<asp:TextBox runat=server ID="PageTypeID" Text='<%#
Bind("PageTypeID") %>' />
</td>
</tr>
<tr>
<tr>
<td>
<p>PageTemplateID</p>
</td>
<td>
<asp:TextBox runat=server ID="PageTemplateID" Text='<%#
Bind("PageTemplateID") %>' />
</td>
</tr>
<tr>
<td>
<p>PageName</p>
</td>
<td>
<asp:TextBox Width=500 runat=server ID="PageName" Text='<%#
Bind("pagename") %>' />
</td>
</tr>
<tr>
<td colspan = "2">
<asp:Button ID="InsertButton" Text="Insert"
CommandName="Insert" runat="server" />
<asp:Button ID="CancelButton" Text="Cancel"
CommandName="Cancel" runat="server" />
</td>
</tr>
</table>
</InsertItemTemplate>
<EmptyDataTemplate>
<asp:Button ID="New" Text="New..." CommandName="New"
runat="server" />
</EmptyDataTemplate>
</asp:FormView>
</form>
</body>
</html>
 

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,818
Messages
2,569,736
Members
45,709
Latest member
DRISenaida

Latest Threads

Top