Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
ASP.NET DataGrid not updating
Old 04-21-2005, 06:16 AM ASP.NET DataGrid not updating
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Trades: 0
Ok this is driving me nuts!
I have a data grid and most of it's working - except the Update button. When I edit, it goes into edit mode correctly, but when I click update, it ignores my changes and reverts back to what it was. Here's my code:

Code:
 <form runat="server">
<div id="divBody">
	<h2>Modify Sections</h2>
	<asp:DataGrid id="dgSections" runat="server" 
	 DataKeyField="ID"
	 AutoGenerateColumns="false"
	 Width="100%"
	 GridLines="None"
	 HeaderStyle-CssClass="ListHead"
	 ItemStyle-CssClass="ListItem"
	 OnEditCommand="dgSections_Edit"
	 OnCancelCommand="dgSections_Cancel"
	 OnUpdateCommand="dgSections_Update"
	 OnDeleteCommand="dgSections_Delete"
	>
	 <Columns>
	 <asp:BoundColumn HeaderText="ID" DataField="ID" ReadOnly="true" />
	 <asp:BoundColumn HeaderText="Title" DataField="Title" />
	 <asp:BoundColumn HeaderText="Description" DataField="Description" />
	 <asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="Update" ItemStyle-Wrap="false" HeaderText="Edit" HeaderStyle-Wrap="false" ButtonType="LinkButton" />
	 <asp:ButtonColumn CommandName="Delete" Text="Remove" HeaderText="Remove" />
	 </Columns>
	</asp:DataGrid>
	<br />
	<asp:ImageButton id="cmdAdd" runat="Server" ImageURL="/images/buttons/add.png" AlternateText="Add" OnClick="cmdAdd_Click" />
</div>
</form>
Code:
<script runat="server">
Sub Page_Load
BindGrid()
End Sub
Sub cmdAdd_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs)
Response.Redirect("add.aspx")
End Sub
Sub dgSections_Edit(sender As Object, e As DataGridCommandEventArgs)
dgSections.EditItemIndex = e.Item.ItemIndex
BindGrid()
End Sub
Sub dgSections_Cancel(sender As Object, e As DataGridCommandEventArgs)
dgSections.EditItemIndex = -1
BindGrid()
End Sub
Sub dgSections_Update(sender As Object, e As DataGridCommandEventArgs)
Dim TitleTxt As System.Web.UI.WebControls.TextBox = e.Item.Cells(1).Controls(0)
Dim DescriptionTxt As System.Web.UI.WebControls.TextBox = e.Item.Cells(2).Controls(0)
Dim ID As Integer = CInt(e.Item.Cells(0).Text)
Dim Title As String = TitleTxt.Text
Dim Description As String = DescriptionTxt.Text
Dim Products As Inoxia.ProductsDB = New Inoxia.ProductsDB()
Dim Section As Inoxia.SectionDetails = New Inoxia.SectionDetails
Section.Title = Title
Section.Description = Description
Dim ErrorText As String = ""
Products.ModifySection(ID, Section)
dgSections.EditItemIndex = -1
BindGrid()
End Sub
Sub dgSections_Delete(sender As Object, e As DataGridCommandEventArgs)
Dim Products As Inoxia.ProductsDB = New Inoxia.ProductsDB()
Dim ID As Integer = CInt(e.Item.Cells(0).Text)
Dim ErrorText As String = ""
If Products.DeleteSection(ID) = False Then ErrorText = "Error deleting section!"
BindGrid()
End Sub
Sub BindGrid()
Dim Products As ProductsDB = New ProductsDB()
dgSections.DataSource = Products.GetSections("ID")
dgSections.DataBind()
End Sub
</script>
I've discovered that in dgSections_Update, TitleTxt.Text and DescriptionTxt.Text contain the old values. It's nothing to do with the database tier cos I've tried setting the Title and Description values staticly and it works...
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
 
Register now for full access!
Old 04-21-2005, 09:22 AM
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Trades: 0
No worries. I'm just being my usual blonde self...

Code:
Sub Page_Load
	If Not Page.IsPostBack Then
		BindGrid()
	End If
End Sub
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Reply     « Reply to ASP.NET DataGrid not updating
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15566 seconds with 12 queries