updating in detailsview

Discussion in '.NET' started by ashishbuddha, Jul 18, 2006.

  1. ashishbuddha

    ashishbuddha

    Joined:
    Jul 18, 2006
    Messages:
    2
    Hello,

    i am using VS 2005 . I am displaying my data in details view and i managed to write the code behind to edit using the "dgrdpro_onmodechanging" sub routing and cancel using "dgrdpro_cancelcommand" can anyone please help me with a example for codebend to update my data when i click update buttom while in editmode.



    Thank you,

    I am copying my code below



    <%@ Import Namespace ="system.data" %>

    <%@ Import Namespace = "system.data.oledb" %>



    <script runat ="server" >


    Dim ConAccess As OleDbConnection

    Sub page_load()

    If Not IsPostBack Then

    binddata()

    End If

    End Sub



    Sub binddata()

    Dim intProId As Integer


    Dim strSelect As String

    Dim cmdselect As OleDbCommand




    'retrieve id

    intProId = Int32.Parse(Request.QueryString("ID"))


    ConAccess = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=C:\Documents and Settings\axb59274\Desktop\PfE New Tables.mdb")

    ConAccess.Open()

    strSelect = "select * from Tbl_Pro where ProID = ?"

    cmdselect = New OleDbCommand(strSelect, ConAccess)

    cmdselect.Parameters.AddWithValue("@ProID", intProId)

    dgrdpro.DataSource = cmdselect.ExecuteReader()

    dgrdpro.DataBind()

    ConAccess.Close()


    End Sub





    Sub dgrdpro_onmodechanging(ByVal s As Object, ByVal e As DetailsViewModeEventArgs)

    If (e.NewMode = DetailsViewMode.Edit) Then


    dgrdpro.ChangeMode(DetailsViewMode.Edit)

    binddata()

    End If

    End Sub


    Sub dgrdpro_cancelcommand(ByVal s As Object, ByVal e As DetailsViewCommandEventArgs)

    If (e.CommandName = "Cancel") Then

    dgrdpro.ChangeMode(DetailsViewMode.ReadOnly)

    End If

    binddata()

    End Sub


    Sub dgrdpro_updatecommand(ByVal s As Object, ByVal e As DetailsViewUpdateEventArgs)

    last = e.NewValues.

    If (e.newmode = DetailsViewMode.Insert) Then

    dgrdpro.ChangeMode(DetailsViewMode.Insert)

    End If

    End Sub





    </script>

    <html xmlns="http://www.w3.org/1999/xhtml" >

    <head id="Head1" runat="server">

    <title>Untitled Page</title>

    </head>

    <body>

    <form id="form1" runat="server">

    <div>

    <asp:Button ID="Button1" runat="server" PostBackUrl="~/New_pro.aspx" Text="Enter New Project" /><br />

    <br />

    <br />

    <asp:DetailsView ID ="dgrdpro"

    OnModeChanging ="dgrdpro_onmodechanging"

    OnItemCommand = "dgrdpro_CancelCommand"

    OnItemUpdating = "dgrdpro_UpdateCommand"




    runat ="server" CellPadding="4" ForeColor="#333333" GridLines="None" AutoGenerateRows ="false" >

    <Fields>

    <asp:TemplateField HeaderText ="ID">

    <ItemTemplate >

    <asp:Label ID = "lblid" runat ="server" Text ='<%#container.dataitem("ProID") %>'></asp:Label>

    </ItemTemplate>

    <EditItemTemplate >

    <asp:label ID ="txtid" runat ="server" Text ='<%#container.dataitem("ProID") %>'></asp:Label>

    </EditItemTemplate>

    </asp:TemplateField>



    <asp:TemplateField HeaderText ="Name">

    <ItemTemplate >

    <asp:Label ID = "lblName" runat ="server" Text ='<%#container.dataitem("ProName") %>'></asp:Label>

    </ItemTemplate>

    <EditItemTemplate >

    <asp:TextBox ID ="txtName" Columns = "50" runat ="server" Text ='<%#container.dataitem("ProName") %>'></asp:TextBox>

    </EditItemTemplate>

    </asp:TemplateField>


    <asp:TemplateField HeaderText ="Description">

    <ItemTemplate >

    <asp:Label ID = "lblDesc" runat ="server" Text ='<%#container.dataitem("ProDesc") %>'></asp:Label>

    </ItemTemplate>

    <EditItemTemplate >

    <asp:TextBox ID ="txtDesc" TextMode ="MultiLine" Columns =50 Rows =7 runat ="server" Text ='<%#container.dataitem("ProDesc") %>'></asp:TextBox>

    </EditItemTemplate>

    </asp:TemplateField>


    <asp:TemplateField HeaderText ="Person">

    <ItemTemplate >

    <asp:Label ID = "lblLast" runat ="server" Text ='<%#container.dataitem("Last") %>'></asp:Label>

    </ItemTemplate>

    <EditItemTemplate >

    <asp:TextBox ID = "DropPerson" runat ="server" Text ='<%#container.dataitem("Last") %>' ></asp:TextBox>

    </EditItemTemplate>

    </asp:TemplateField>


    <asp:TemplateField HeaderText ="Business ID">

    <ItemTemplate >

    <asp:Label ID = "lblBuss" runat ="server" Text ='<%#container.dataitem("Business ID") %>'></asp:Label>

    </ItemTemplate>

    <EditItemTemplate >

    <asp:TextBox ID ="txtBuss" runat ="server" Text ='<%#container.dataitem("Business ID") %>'></asp:TextBox>

    </EditItemTemplate>

    </asp:TemplateField>



    <asp:TemplateField HeaderText ="Team">

    <ItemTemplate >

    <asp:Label ID = "lblTeam" runat ="server" Text ='<%#container.dataitem("TeamID") %>'></asp:Label>

    </ItemTemplate>

    <EditItemTemplate >

    <asp:DropDownList ID ="dropteam" runat ="server" EnableViewState ="true" selectedvalue = '<%#container.dataitem("TeamID") %>'>


    <asp:ListItem>CST</asp:ListItem>

    <asp:ListItem>EHM</asp:ListItem>

    <asp:ListItem>EHS</asp:ListItem>

    <asp:ListItem>EXT</asp:ListItem>

    <asp:ListItem>GAT</asp:ListItem>

    <asp:ListItem>GBS</asp:ListItem>

    <asp:ListItem>HAC</asp:ListItem>

    <asp:ListItem>PS</asp:ListItem>

    <asp:ListItem>REP</asp:ListItem>

    <asp:ListItem>SD</asp:ListItem>

    <asp:ListItem>SER</asp:ListItem>




    </asp:DropDownList>

    </EditItemTemplate>

    </asp:TemplateField>


    <asp:TemplateField HeaderText ="Estimated Beginning">

    <ItemTemplate >

    <asp:Label ID = "lblEBeg" runat ="server" Text ='<%#container.dataitem("ProEBeg") %>'></asp:Label>

    </ItemTemplate>

    <EditItemTemplate >

    <asp:TextBox ID ="txtEbeg" runat ="server" Text ='<%#container.dataitem("ProEbeg") %>'></asp:TextBox>

    </EditItemTemplate>

    </asp:TemplateField>


    <asp:TemplateField HeaderText ="Estimated Ending">

    <ItemTemplate >

    <asp:Label ID = "lblEEnd" runat ="server" Text ='<%#container.dataitem("ProEEnd") %>'></asp:Label>

    </ItemTemplate>

    <EditItemTemplate >

    <asp:TextBox ID ="txtEEnd" runat ="server" Text ='<%#container.dataitem("ProEEnd") %>'></asp:TextBox>

    </EditItemTemplate>

    </asp:TemplateField>


    <asp:TemplateField HeaderText ="Actual Beginning">

    <ItemTemplate >

    <asp:Label ID = "lblABeg" runat ="server" Text ='<%#container.dataitem("ProABeg") %>'></asp:Label>

    </ItemTemplate>

    <EditItemTemplate >

    <asp:TextBox ID ="txtAbeg" runat ="server" Text ='<%#container.dataitem("ProAbeg") %>'></asp:TextBox>

    </EditItemTemplate>

    </asp:TemplateField>


    <asp:TemplateField HeaderText ="Actual Ending">

    <ItemTemplate >

    <asp:Label ID = "lblAEnd" runat ="server" Text ='<%#container.dataitem("ProAEnd") %>'></asp:Label>

    </ItemTemplate>

    <EditItemTemplate >

    <asp:TextBox ID ="txtAEnd" runat ="server" Text ='<%#container.dataitem("ProAEnd") %>'></asp:TextBox>

    </EditItemTemplate>

    </asp:TemplateField>


    <asp:TemplateField HeaderText ="Status">

    <ItemTemplate >

    <asp:Label ID = "lblStatus" runat ="server" Text ='<%#container.dataitem("Status") %>'></asp:Label>

    </ItemTemplate>

    <EditItemTemplate >

    <asp:TextBox ID ="txtstatus" runat ="server" Text ='<%#container.dataitem("status") %>'></asp:TextBox>

    </EditItemTemplate>

    </asp:TemplateField>


    <asp:TemplateField HeaderText ="Start Date">

    <ItemTemplate >

    <asp:Label ID = "lblstat" runat ="server" Text ='<%#container.dataitem("statdate") %>'></asp:Label>

    </ItemTemplate>

    <EditItemTemplate >

    <asp:TextBox ID ="txtstat" runat ="server" Text ='<%#container.dataitem("StatDate") %>'></asp:TextBox>

    </EditItemTemplate>

    </asp:TemplateField>


    <asp:TemplateField HeaderText ="Fundamental ID">

    <ItemTemplate >

    <asp:Label ID = "lblFun" runat ="server" Text ='<%#container.dataitem("FunID") %>'></asp:Label>

    </ItemTemplate>

    <EditItemTemplate >

    <asp:TextBox ID ="txtFun" runat ="server" Text ='<%#container.dataitem("FunID") %>'></asp:TextBox>

    </EditItemTemplate>

    </asp:TemplateField>



    <asp:TemplateField HeaderText ="Project Type">

    <ItemTemplate >

    <asp:Label ID = "lblType" runat ="server" Text ='<%#container.dataitem("ProType") %>'></asp:Label>

    </ItemTemplate>

    <EditItemTemplate >

    <asp:TextBox ID ="txtType" runat ="server" Text ='<%#container.dataitem("ProType") %>'></asp:TextBox>

    </EditItemTemplate>

    </asp:TemplateField>



    <asp:HyperLinkField DataNavigateUrlFields="ProID" DataNavigateUrlFormatString="Objectives.aspx?Id={0}"

    HeaderText="Objectives" Text="View Objectives" />

    <asp:HyperLinkField DataNavigateUrlFields="ProID" DataNavigateUrlFormatString="Resources.aspx?id={0}"

    HeaderText="Resources" Text="View Resources" />

    <asp:HyperLinkField DataNavigateUrlFields="ProId" DataNavigateUrlFormatString="Milestones.aspx?Id={0}"

    HeaderText="MileStones" Text="View Milestones" />



    <asp:TemplateField>


    <ItemTemplate>

    <asp:Button ID="Button1" runat="server" Width ="60" CausesValidation="false" CommandName="Edit" Text="Edit"></asp:Button>

    </ItemTemplate>

    <EditItemTemplate>

    <asp:Button ID="Button2" runat="server" CommandName="Update" Text="Update"></asp:Button>

    <asp:Button ID="Button3" runat="server" CausesValidation="false" CommandName="Cancel" Text="Cancel"></asp:Button>

    </EditItemTemplate>

    </asp:TemplateField>


    </Fields>

    </asp:DetailsView><br />

    </div>

    </form>

    </body>

    </html>
    ashishbuddha, Jul 18, 2006
    #1
    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. Roger
    Replies:
    1
    Views:
    454
    joeka
    Nov 17, 2005
  2. stuart.d.jones@gmail.com

    Catch errors when updating a DetailsView control

    stuart.d.jones@gmail.com, Jan 25, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    4,486
    stuart.d.jones@gmail.com
    Jan 26, 2006
  3. David Lozzi

    DetailsView not updating

    David Lozzi, Jan 5, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    540
    Mark Rae
    Jan 9, 2007
  4. 47computers@gmail.com

    Inserting/Updating records in a DetailsView

    47computers@gmail.com, Mar 28, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    357
    47computers@gmail.com
    Mar 28, 2007
  5. Feege
    Replies:
    0
    Views:
    428
    Feege
    Dec 20, 2005
Loading...

Share This Page