DetailView

Discussion in 'ASP .Net' started by viktor, Jul 30, 2007.

  1. viktor

    viktor Guest

    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
     
    viktor, Jul 30, 2007
    #1
    1. Advertising

  2. viktor

    Brandon Gano Guest

    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" <> wrote in message
    news:%...
    >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
    >
    >
     
    Brandon Gano, Jul 30, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kha Tran
    Replies:
    0
    Views:
    572
    Kha Tran
    Jun 3, 2005
  2. =?Utf-8?B?QXJuZQ==?=

    DetailView

    =?Utf-8?B?QXJuZQ==?=, Jan 26, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    1,852
    msnews.microsoft.com
    Jan 27, 2006
  3. Mike
    Replies:
    0
    Views:
    486
  4. Henry Lee

    DetailView Data Update Error

    Henry Lee, Mar 2, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    962
    Henry Lee
    Mar 2, 2006
  5. =?Utf-8?B?Sm9obiBCYWlsZXk=?=

    Formating a date field in ASP .Net 2.0 detailview

    =?Utf-8?B?Sm9obiBCYWlsZXk=?=, Mar 29, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    3,872
    elizas
    Apr 29, 2010
Loading...

Share This Page