DetailView


V

viktor

I am having a problem cahnging default mode in the code.What i am trying to
do is: on page load event:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load

If Page.IsPostBack Then

itemview.DefaultMode = DetailsViewMode.ReadOnly

Else

itemview.DefaultMode = DetailsViewMode.Insert

End If

End Sub



i have a txt box and when i change a value and hit enter to post back it
doesn't change the mode on detailsview.

here my aspx code:

<%@ Page Language="VB" MasterPageFile="~/AppMaster.master"
AutoEventWireup="false" CodeFile="Inventory_entry.aspx.vb"
Inherits="admin_customer_Inventory_entry" title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="mainCopy" Runat="Server">

<br />Item Id:


<asp:TextBox ID="itemID" runat="server" Text='<%# Bind("item_id") %>'
AutoPostBack="True"></asp:TextBox>&nbsp;<asp:Button

ID="Button1" runat="server" Text="Button" /><br />

<br />

<asp:DetailsView ID="itemview" runat="server" AutoGenerateRows="False"
DataKeyNames="inv_mast_uid"

DataSourceID="inventoryateset" Height="50px" Width="219px">

<Fields>

<asp:BoundField DataField="inv_mast_uid" HeaderText="inv_mast_uid"
InsertVisible="False"

ReadOnly="True" SortExpression="inv_mast_uid" />

<asp:BoundField DataField="item_id" HeaderText="item_id"
SortExpression="item_id" />

<asp:BoundField DataField="item_description" HeaderText="item_description"
SortExpression="item_description" />

<asp:BoundField DataField="qty_on_hand" HeaderText="qty_on_hand"
SortExpression="qty_on_hand" />

<asp:BoundField DataField="uom" HeaderText="uom" SortExpression="uom" />

<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
ShowInsertButton="True" />

</Fields>

</asp:DetailsView>

<asp:SqlDataSource ID="inventoryateset" runat="server"
ConflictDetection="CompareAllValues"

ConnectionString="<%$ ConnectionStrings:KeaneConnectionString %>"
DeleteCommand="DELETE FROM [inventory] WHERE [inv_mast_uid] =
@original_inv_mast_uid AND [item_id] = @original_item_id AND
[item_description] = @original_item_description AND [qty_on_hand] =
@original_qty_on_hand AND [uom] = @original_uom"

InsertCommand="INSERT INTO [inventory] ([item_id], [item_description],
[qty_on_hand], [uom]) VALUES (@item_id, @item_description, @qty_on_hand,
@uom)"

OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM
[inventory] WHERE ([item_id] = @item_id)"

UpdateCommand="UPDATE [inventory] SET [item_id] = @item_id,
[item_description] = @item_description, [qty_on_hand] = @qty_on_hand, [uom]
= @uom WHERE [inv_mast_uid] = @original_inv_mast_uid AND [item_id] =
@original_item_id AND [item_description] = @original_item_description AND
[qty_on_hand] = @original_qty_on_hand AND [uom] = @original_uom">

<DeleteParameters>

<asp:parameter Name="original_inv_mast_uid" Type="Int32" />

<asp:parameter Name="original_item_id" Type="String" />

<asp:parameter Name="original_item_description" Type="String" />

<asp:parameter Name="original_qty_on_hand" Type="Decimal" />

<asp:parameter Name="original_uom" Type="String" />

</DeleteParameters>

<UpdateParameters>

<asp:parameter Name="item_id" Type="String" />

<asp:parameter Name="item_description" Type="String" />

<asp:parameter Name="qty_on_hand" Type="Decimal" />

<asp:parameter Name="uom" Type="String" />

<asp:parameter Name="original_inv_mast_uid" Type="Int32" />

<asp:parameter Name="original_item_id" Type="String" />

<asp:parameter Name="original_item_description" Type="String" />

<asp:parameter Name="original_qty_on_hand" Type="Decimal" />

<asp:parameter Name="original_uom" Type="String" />

</UpdateParameters>

<SelectParameters>

<asp:ControlParameter ControlID="itemID" Name="item_id" PropertyName="Text"
Type="String" />

</SelectParameters>

<InsertParameters>

<asp:parameter Name="item_id" Type="String" />

<asp:parameter Name="item_description" Type="String" />

<asp:parameter Name="qty_on_hand" Type="Decimal" />

<asp:parameter Name="uom" Type="String" />

</InsertParameters>

</asp:SqlDataSource>

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="leftColumn" Runat="Server">

</asp:Content>



ANY HELP PLEASE
 
Ad

Advertisements

B

Brandon Gano

Try moving that code to Page_Init. I think the viewstate is being saved
before you make that change, so it doesn't push through to the output.


viktor said:
I am having a problem cahnging default mode in the code.What i am trying to
do is: on page load event:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

If Page.IsPostBack Then

itemview.DefaultMode = DetailsViewMode.ReadOnly

Else

itemview.DefaultMode = DetailsViewMode.Insert

End If

End Sub



i have a txt box and when i change a value and hit enter to post back it
doesn't change the mode on detailsview.

here my aspx code:

<%@ Page Language="VB" MasterPageFile="~/AppMaster.master"
AutoEventWireup="false" CodeFile="Inventory_entry.aspx.vb"
Inherits="admin_customer_Inventory_entry" title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="mainCopy" Runat="Server">

<br />Item Id:


<asp:TextBox ID="itemID" runat="server" Text='<%# Bind("item_id") %>'
AutoPostBack="True"></asp:TextBox>&nbsp;<asp:Button

ID="Button1" runat="server" Text="Button" /><br />

<br />

<asp:DetailsView ID="itemview" runat="server" AutoGenerateRows="False"
DataKeyNames="inv_mast_uid"

DataSourceID="inventoryateset" Height="50px" Width="219px">

<Fields>

<asp:BoundField DataField="inv_mast_uid" HeaderText="inv_mast_uid"
InsertVisible="False"

ReadOnly="True" SortExpression="inv_mast_uid" />

<asp:BoundField DataField="item_id" HeaderText="item_id"
SortExpression="item_id" />

<asp:BoundField DataField="item_description" HeaderText="item_description"
SortExpression="item_description" />

<asp:BoundField DataField="qty_on_hand" HeaderText="qty_on_hand"
SortExpression="qty_on_hand" />

<asp:BoundField DataField="uom" HeaderText="uom" SortExpression="uom" />

<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
ShowInsertButton="True" />

</Fields>

</asp:DetailsView>

<asp:SqlDataSource ID="inventoryateset" runat="server"
ConflictDetection="CompareAllValues"

ConnectionString="<%$ ConnectionStrings:KeaneConnectionString %>"
DeleteCommand="DELETE FROM [inventory] WHERE [inv_mast_uid] =
@original_inv_mast_uid AND [item_id] = @original_item_id AND
[item_description] = @original_item_description AND [qty_on_hand] =
@original_qty_on_hand AND [uom] = @original_uom"

InsertCommand="INSERT INTO [inventory] ([item_id], [item_description],
[qty_on_hand], [uom]) VALUES (@item_id, @item_description, @qty_on_hand,
@uom)"

OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM
[inventory] WHERE ([item_id] = @item_id)"

UpdateCommand="UPDATE [inventory] SET [item_id] = @item_id,
[item_description] = @item_description, [qty_on_hand] = @qty_on_hand,
[uom] = @uom WHERE [inv_mast_uid] = @original_inv_mast_uid AND [item_id] =
@original_item_id AND [item_description] = @original_item_description AND
[qty_on_hand] = @original_qty_on_hand AND [uom] = @original_uom">

<DeleteParameters>

<asp:parameter Name="original_inv_mast_uid" Type="Int32" />

<asp:parameter Name="original_item_id" Type="String" />

<asp:parameter Name="original_item_description" Type="String" />

<asp:parameter Name="original_qty_on_hand" Type="Decimal" />

<asp:parameter Name="original_uom" Type="String" />

</DeleteParameters>

<UpdateParameters>

<asp:parameter Name="item_id" Type="String" />

<asp:parameter Name="item_description" Type="String" />

<asp:parameter Name="qty_on_hand" Type="Decimal" />

<asp:parameter Name="uom" Type="String" />

<asp:parameter Name="original_inv_mast_uid" Type="Int32" />

<asp:parameter Name="original_item_id" Type="String" />

<asp:parameter Name="original_item_description" Type="String" />

<asp:parameter Name="original_qty_on_hand" Type="Decimal" />

<asp:parameter Name="original_uom" Type="String" />

</UpdateParameters>

<SelectParameters>

<asp:ControlParameter ControlID="itemID" Name="item_id"
PropertyName="Text" Type="String" />

</SelectParameters>

<InsertParameters>

<asp:parameter Name="item_id" Type="String" />

<asp:parameter Name="item_description" Type="String" />

<asp:parameter Name="qty_on_hand" Type="Decimal" />

<asp:parameter Name="uom" Type="String" />

</InsertParameters>

</asp:SqlDataSource>

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="leftColumn"
Runat="Server">

</asp:Content>



ANY HELP PLEASE
 

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