Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > updating in detailsview

Reply
Thread Tools

updating in detailsview

 
 
ashishbuddha ashishbuddha is offline
Junior Member
Join Date: Jul 2006
Posts: 2
 
      07-18-2006
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 />

<aspetailsView 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 >

<aspropDownList 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>




</aspropDownList>

</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>

</aspetailsView><br />

</div>

</form>

</body>

</html>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting/Updating records in a DetailsView 47computers@gmail.com ASP .Net 0 03-28-2007 12:49 AM
DetailsView not updating David Lozzi ASP .Net 2 01-09-2007 04:18 PM
Catch errors when updating a DetailsView control stuart.d.jones@gmail.com ASP .Net 3 01-26-2006 12:32 PM
DetailsView - Changing to Insert Mode (Not By Using the Insert Button In the DetailsView Control) Feege ASP .Net Web Controls 0 12-20-2005 12:28 AM
Updating with DetailsView Control - ASP.net2 Roger ASP .Net 1 11-17-2005 10:20 AM



Advertisments