How to update Gridview


R

RAB

I have created a web site using asp.net 2.0. One of my pages has the
following code:

<%@ Page Language="VB" MasterPageFile="~/Default.master"
AutoEventWireup="false" CodeFile="Add_Dept.aspx.vb"
Inherits="Sched_Admin_Add_Dept" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
<br />


<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="Dept_Id"
DataSourceID="SqlDataSource_GetDepartments">
<Columns>
<asp:CommandField ShowDeleteButton="True"
ShowEditButton="True" ShowSelectButton="True" />
<asp:BoundField DataField="Dept_Id" HeaderText="Dept_Id"
InsertVisible="False" ReadOnly="True"
SortExpression="Dept_Id" />
<asp:BoundField DataField="Dept_Name"
HeaderText="Dept_Name" SortExpression="Dept_Name" />
</Columns>
</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource_GetDepartments" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"
DeleteCommand="DELETE FROM [Departments] WHERE [Dept_Id] =
@original_Dept_Id AND [Dept_Name] = @original_Dept_Name"
InsertCommand="INSERT INTO [Departments] ([Dept_Name]) VALUES
(@Dept_Name)" OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT * FROM [Departments] ORDER BY
[Dept_Name]" UpdateCommand="UPDATE [Departments] SET [Dept_Name] =
@Dept_Name WHERE [Dept_Id] = @original_Dept_Id AND [Dept_Name] =
@original_Dept_Name">
<DeleteParameters>
<asp:parameter Name="original_Dept_Id" Type="Int32" />
<asp:parameter Name="original_Dept_Name" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:parameter Name="Dept_Name" Type="String" />
<asp:parameter Name="original_Dept_Id" Type="Int32" />
<asp:parameter Name="original_Dept_Name" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:parameter Name="Dept_Name" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<br />

<asp:DetailsView ID="DetailsView1" runat="server"
AutoGenerateRows="False"
DataKeyNames="Dept_Id"
DataSourceID="SqlDataSource_AddDepartments" Height="50px"
Width="125px" CellPadding="4" ForeColor="#333333"
GridLines="None" DefaultMode="Insert">
<Fields>
<asp:BoundField DataField="Dept_Id" HeaderText="Dept_Id"
InsertVisible="False" ReadOnly="True"
SortExpression="Dept_Id" Visible="False" />
<asp:BoundField DataField="Dept_Name"
HeaderText="Department Name" SortExpression="Dept_Name" />
<asp:CommandField ShowInsertButton="True" />
</Fields>
<FooterStyle BackColor="#507CD1" Font-Bold="True"
ForeColor="White" />
<CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
<RowStyle BackColor="#EFF3FB" />
<FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" />
<PagerStyle BackColor="#2461BF" ForeColor="White"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True"
ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:DetailsView>

<asp:SqlDataSource ID="SqlDataSource_AddDepartments" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"
DeleteCommand="DELETE FROM [Departments] WHERE [Dept_Id] =
@original_Dept_Id AND [Dept_Name] = @original_Dept_Name"
InsertCommand="INSERT INTO [Departments] ([Dept_Name]) VALUES
(@Dept_Name)" OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT * FROM [Departments]"
UpdateCommand="UPDATE [Departments] SET [Dept_Name] = @Dept_Name WHERE
[Dept_Id] = @original_Dept_Id AND [Dept_Name] = @original_Dept_Name">
<DeleteParameters>
<asp:parameter Name="original_Dept_Id" Type="Int32" />
<asp:parameter Name="original_Dept_Name" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:parameter Name="Dept_Name" Type="String" />
<asp:parameter Name="original_Dept_Id" Type="Int32" />
<asp:parameter Name="original_Dept_Name" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:parameter Name="Dept_Name" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<br />
<br />
<br />
&nbsp;<br />
<br />
</asp:Content>

After I insert a new department into the database using the
Detailsview how can the new department be seen in the Gridview
without having to refresh the page?

Thanks in advance,
RABMissouri2010
 
Ad

Advertisements


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

Top