(forgot to put the code behind file into the code box)
What we have so far:
I'm hoping the above two files work for you. If so, then you have a FormView that inserts and a FormView below that where you can click on a number to call up an entry, and then type your changes and click Update when you are finished.
I forgot to change the TextBoxes for the definition field to have TextMode set to Multiline (so if you type a long sentence it wraps around when you get to the right edge of the TextBox.
So far the code is mostly just putting server controls on a page. I have been making two changes though. I set the height and width of the TextBox (for both Insert and Edit) to 80px height and 560px width so you'd have something larger. Also, for the
Gridview, I changed
asp:GridView
to have the following because without it, everything is "crammed" together and I find that hard to read.
So far the code is mostly just putting server controls on a page. I have been making two changes though. I set the height and width of the TextBox (for both Insert and Edit) to 80px height and 560px width so you'd have something larger. Also, for the
Gridview, I changed
asp:GridView
to have the following because without it, everything is "crammed" together and I find that hard to read.
CellPadding="4"
CellSpacing="8"
I await your feedback to see where we go next.
-Larry
Hi Larry,
OK so far...I had to clean up the C# page to look like this:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Eyetech2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
...but all is working.
One of the reasons I have avoided the formview control is that the 'barebones' templates are sloppy and ugly and to make them a little more elegant takes a bit of editing and with tables somewhat larger than the dictionary example it is very time-consuming.
With the detailsview, on the other hand, you get a nice looking 'form' right away and that is much more convenient for rapid development. But let's carry on...
I haven't tried a DetailsView yet, so that's my next mission.
Meanwhile, where would you like us to take this from here? May I assume that at this point, the question of the controls not working is resolved? I consider "working" or functionality to be level 1, and at level 2 I put security, stability, efficiency
and esthetics (aesthetics). Wonder what Maslow would say...
I haven't tried a DetailsView yet, so that's my next mission.
Meanwhile, where would you like us to take this from here? May I assume that at this point, the question of the controls not working is resolved? I consider "working" or functionality to be level 1, and at level 2 I put security, stability, efficiency
and esthetics (aesthetics). Wonder what Maslow would say...
Cheers,
-Larry
At this point, it would be interesting to know what you say to this next little test. While I was waiting for this reply, I created a new page, dropped a gridview on it and set the datasource to point to our new dictionary table, set it to include update
and delete...it works fine. Deleted those and added a gridview again this time connecting the datasource to MY table with the update and delete options. It doesn't work.
So...I guess that must mean there is something wrong with MY Table???
I had created my table originally with a TEXT value for the primary key and, of course no identity setting since it wouldn't work with a text value.
I changed it to a numeric and set isidentity yes,1,1 as in our example.
Still nothing.
I've tried pasting some of my source code here, but it's truncating it...I don't know why...so that you would at least be able to see the control structure.
Very quickly losing the faith! Even Microsoft can't get things to work on their site!
I DELETED my Database and recreated it from scratch using a numeric UID {primary key} Identity yes,1,1101
Added a test row of data.
Created a new form. Added Gridview1 on sqldatasource1 selecting only the UID and the next two fields; set allow SELECT allow SORTING. Added Detailsview1 on sqldatasource2 selecting * fields. Did Bob Tabor's little linking code trick on the gridview1_SelectedIndexChanged
event.
Run in DEBUG...
EDIT the record...goes into edit mode. Click UPDATE...NOTHING HAPPENS. Close the page check the data in the table...NO CHANGE.
Run in DEBUG again...
Click INSERT...get the insert form...add the data...click INSERT...page refreshes but there is no new record. (But wait...)
Close the page...check the data in the Table...LOW AND BEHOLD TWO IDENTICAL ROWS HAVE BEEN INSERTED. (Except for the UID of course which is maintained by the system, but it had incremented properly. Hooray!)
Back to page in DEBUG...SELECT the last row on the gridview...detailsview refreshes with the correct record. Remember, this is the duplicate of the row above it. EDIT...change data...UPDATE. NOTHING!
Close page look in Table...no changes to last row. (Do quick manual edit to 'unduplicate' the data by putting in some other data! Close Table.
Back to form...check source. Everything looks fine...EXCEPT THE DUPLICATE SET OF UPDATE PARAMETERS FOR THE DETAILSVIEW CONTROL! (Sheesh...this just gets better and better with time...it must think it's Wine! [:S]) Delete the duplicate parameters...save form.
Try again.
Insert a row...nothing happens on the form when INSERT is clicked, but two rows are inserted into the table--exact same data.
Try to update from the form again...NOTHING. It just doesn't make any sense, does it? I can use your example, Larry, and it works fine. Recreate my own table...and BUST! Are there some bizarre Undocumented RULES for these controls? Can anyone else offer
some words of wisdom? Or perhaps it's better I go back to THE OLD WAY of doing things and abandon .NET! Something totally out of character for me, but I'd consider it since we know it will work!
And the big question...WILL THIS WORK IF I PAY FOR SOFTWARE???? EXPRESS is
not paving the way for NON-EXPRESS in MY office, I'll tell ya, gang! I'm glad I still have Visual Studio 6 and FrontPage still installed.
Could you post for me the code that you are using? (taking care to change personal information, passwords, etc.)
First time I posted code here...it worked fine as you saw...last time I tried to post code here (with a source code box, of course)...it got mangled. So here goes nuttin'.
...much time passes...
Sorry Larry...I cannot seem to past any code either in a source code box or directly into the message without it being truncated. Any thoughts...I'll try a separate message and see what happens.
ldechent
Contributor
6326 Points
1577 Posts
Re: Two pages of complete code (one is a code behind) - I use C#
Jan 23, 2007 11:31 AM|LINK
(forgot to put the code behind file into the code box)
What we have so far:
I'm hoping the above two files work for you. If so, then you have a FormView that inserts and a FormView below that where you can click on a number to call up an entry, and then type your changes and click Update when you are finished.
I forgot to change the TextBoxes for the definition field to have TextMode set to Multiline (so if you type a long sentence it wraps around when you get to the right edge of the TextBox.
ldechent
Contributor
6326 Points
1577 Posts
Re: Two pages of complete code (one is a code behind) - I use C#
Jan 23, 2007 11:40 AM|LINK
updated version of Eyetech2.aspx (includes setting the TextMode to Multiline for two TextBoxes)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Eyetech2.aspx.cs" Inherits="Eyetech2" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" DeleteCommand="DELETE FROM [dictionary] WHERE [id] = @original_id AND [word] = @original_word AND [definition] = @original_definition" InsertCommand="INSERT INTO [dictionary] ([word], [definition]) VALUES (@word, @definition)" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [dictionary]" UpdateCommand="UPDATE [dictionary] SET [word] = @word, [definition] = @definition WHERE [id] = @original_id AND [word] = @original_word AND [definition] = @original_definition"> <DeleteParameters> <asp:Parameter Name="original_id" Type="Int16" /> <asp:Parameter Name="original_word" Type="String" /> <asp:Parameter Name="original_definition" Type="String" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="word" Type="String" /> <asp:Parameter Name="definition" Type="String" /> <asp:Parameter Name="original_id" Type="Int16" /> <asp:Parameter Name="original_word" Type="String" /> <asp:Parameter Name="original_definition" Type="String" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="word" Type="String" /> <asp:Parameter Name="definition" Type="String" /> </InsertParameters> </asp:SqlDataSource> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" CellSpacing="8" DataKeyNames="id" DataSourceID="SqlDataSource1"> <Columns> <asp:CommandField ShowDeleteButton="True" /> <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True" SortExpression="id" /> <asp:BoundField DataField="word" HeaderText="word" SortExpression="word" /> <asp:BoundField DataField="definition" HeaderText="definition" SortExpression="definition" /> </Columns> </asp:GridView> <asp:FormView ID="FormView1" runat="server" DataKeyNames="id" DataSourceID="SqlDataSource1" DefaultMode="Insert"> <EditItemTemplate> id: <asp:Label ID="idLabel1" runat="server" Text='<%# Eval("id") %>'></asp:Label><br /> word: <asp:TextBox ID="wordTextBox" runat="server" Text='<%# Bind("word") %>'> </asp:TextBox><br /> definition: <asp:TextBox ID="definitionTextBox" runat="server" Text='<%# Bind("definition") %>'> </asp:TextBox><br /> <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update"> </asp:LinkButton> <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"> </asp:LinkButton> </EditItemTemplate> <InsertItemTemplate> word: <asp:TextBox ID="wordTextBox" runat="server" Text='<%# Bind("word") %>'></asp:TextBox><br /> definition: <asp:TextBox ID="definitionTextBox" runat="server" Height="80px" Text='<%# Bind("definition") %>' Width="560px" TextMode="MultiLine"></asp:TextBox><br /> <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert"></asp:LinkButton> <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton> </InsertItemTemplate> <ItemTemplate> id: <asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>'></asp:Label><br /> word: <asp:Label ID="wordLabel" runat="server" Text='<%# Bind("word") %>'></asp:Label><br /> definition: <asp:Label ID="definitionLabel" runat="server" Text='<%# Bind("definition") %>'></asp:Label><br /> <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton> <asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete"></asp:LinkButton> <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New" Text="New"></asp:LinkButton> </ItemTemplate> </asp:FormView> <asp:FormView ID="FormView2" runat="server" AllowPaging="True" DataKeyNames="id" DataSourceID="SqlDataSource1" DefaultMode="Edit"> <EditItemTemplate> id: <asp:Label ID="idLabel1" runat="server" Text='<%# Eval("id") %>'></asp:Label><br /> word: <asp:TextBox ID="wordTextBox" runat="server" Text='<%# Bind("word") %>'></asp:TextBox><br /> definition: <asp:TextBox ID="definitionTextBox" runat="server" Height="80px" Text='<%# Bind("definition") %>' Width="560px" TextMode="MultiLine"></asp:TextBox><br /> <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton> <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton> </EditItemTemplate> <InsertItemTemplate> word: <asp:TextBox ID="wordTextBox" runat="server" Text='<%# Bind("word") %>'> </asp:TextBox><br /> definition: <asp:TextBox ID="definitionTextBox" runat="server" Text='<%# Bind("definition") %>'> </asp:TextBox><br /> <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert"> </asp:LinkButton> <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"> </asp:LinkButton> </InsertItemTemplate> <ItemTemplate> id: <asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>'></asp:Label><br /> word: <asp:Label ID="wordLabel" runat="server" Text='<%# Bind("word") %>'></asp:Label><br /> definition: <asp:Label ID="definitionLabel" runat="server" Text='<%# Bind("definition") %>'></asp:Label><br /> <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton> <asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete"></asp:LinkButton> <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New" Text="New"></asp:LinkButton> </ItemTemplate> </asp:FormView> </div> </form> </body> </html>So far the code is mostly just putting server controls on a page. I have been making two changes though. I set the height and width of the TextBox (for both Insert and Edit) to 80px height and 560px width so you'd have something larger. Also, for the Gridview, I changed
asp:GridView
to have the following because without it, everything is "crammed" together and I find that hard to read.
CellPadding="4" CellSpacing="8"
I await your feedback to see where we go next.
-Larry
eyetech
Member
21 Points
49 Posts
Re: Two pages of complete code (one is a code behind) - I use C#
Jan 23, 2007 02:44 PM|LINK
Hi Larry,
OK so far...I had to clean up the C# page to look like this:
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class Eyetech2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } }...but all is working.
One of the reasons I have avoided the formview control is that the 'barebones' templates are sloppy and ugly and to make them a little more elegant takes a bit of editing and with tables somewhat larger than the dictionary example it is very time-consuming. With the detailsview, on the other hand, you get a nice looking 'form' right away and that is much more convenient for rapid development. But let's carry on...
ldechent
Contributor
6326 Points
1577 Posts
Re: Update, Delete in Gridview and Detailsview controls don't work
Jan 23, 2007 03:25 PM|LINK
OK.
I haven't tried a DetailsView yet, so that's my next mission.
Meanwhile, where would you like us to take this from here? May I assume that at this point, the question of the controls not working is resolved? I consider "working" or functionality to be level 1, and at level 2 I put security, stability, efficiency and esthetics (aesthetics). Wonder what Maslow would say...
Cheers,
-Larry
eyetech
Member
21 Points
49 Posts
Re: Update, Delete in Gridview and Detailsview controls don't work
Jan 23, 2007 04:10 PM|LINK
At this point, it would be interesting to know what you say to this next little test. While I was waiting for this reply, I created a new page, dropped a gridview on it and set the datasource to point to our new dictionary table, set it to include update and delete...it works fine. Deleted those and added a gridview again this time connecting the datasource to MY table with the update and delete options. It doesn't work.
So...I guess that must mean there is something wrong with MY Table???
I had created my table originally with a TEXT value for the primary key and, of course no identity setting since it wouldn't work with a text value.
I changed it to a numeric and set isidentity yes,1,1 as in our example.
Still nothing.
I've tried pasting some of my source code here, but it's truncating it...I don't know why...so that you would at least be able to see the control structure.
Very quickly losing the faith! Even Microsoft can't get things to work on their site!
eyetech
Member
21 Points
49 Posts
Re: Update, Delete in Gridview and Detailsview controls don't work
Jan 24, 2007 01:22 AM|LINK
Here is my latest experiment.
I DELETED my Database and recreated it from scratch using a numeric UID {primary key} Identity yes,1,1101
Added a test row of data.
Created a new form. Added Gridview1 on sqldatasource1 selecting only the UID and the next two fields; set allow SELECT allow SORTING. Added Detailsview1 on sqldatasource2 selecting * fields. Did Bob Tabor's little linking code trick on the gridview1_SelectedIndexChanged event.
Run in DEBUG...
EDIT the record...goes into edit mode. Click UPDATE...NOTHING HAPPENS. Close the page check the data in the table...NO CHANGE.
Run in DEBUG again...
Click INSERT...get the insert form...add the data...click INSERT...page refreshes but there is no new record. (But wait...)
Close the page...check the data in the Table...LOW AND BEHOLD TWO IDENTICAL ROWS HAVE BEEN INSERTED. (Except for the UID of course which is maintained by the system, but it had incremented properly. Hooray!)
Back to page in DEBUG...SELECT the last row on the gridview...detailsview refreshes with the correct record. Remember, this is the duplicate of the row above it. EDIT...change data...UPDATE. NOTHING!
Close page look in Table...no changes to last row. (Do quick manual edit to 'unduplicate' the data by putting in some other data! Close Table.
Back to form...check source. Everything looks fine...EXCEPT THE DUPLICATE SET OF UPDATE PARAMETERS FOR THE DETAILSVIEW CONTROL! (Sheesh...this just gets better and better with time...it must think it's Wine! [:S]) Delete the duplicate parameters...save form. Try again.
Insert a row...nothing happens on the form when INSERT is clicked, but two rows are inserted into the table--exact same data.
Try to update from the form again...NOTHING. It just doesn't make any sense, does it? I can use your example, Larry, and it works fine. Recreate my own table...and BUST! Are there some bizarre Undocumented RULES for these controls? Can anyone else offer some words of wisdom? Or perhaps it's better I go back to THE OLD WAY of doing things and abandon .NET! Something totally out of character for me, but I'd consider it since we know it will work!
And the big question...WILL THIS WORK IF I PAY FOR SOFTWARE???? EXPRESS is not paving the way for NON-EXPRESS in MY office, I'll tell ya, gang! I'm glad I still have Visual Studio 6 and FrontPage still installed.
eyetech
Member
21 Points
49 Posts
Re: Update, Delete in Gridview and Detailsview controls don't work
Jan 24, 2007 01:36 AM|LINK
Just an added note...tried DELETE.
It doesn't work either! Should I be suprised?[+o(]
ldechent
Contributor
6326 Points
1577 Posts
Re: Update, Delete in Gridview and Detailsview controls don't work
Jan 24, 2007 01:40 AM|LINK
eyetech
Member
21 Points
49 Posts
Re: Update, Delete in Gridview and Detailsview controls don't work
Jan 24, 2007 02:41 AM|LINK
First time I posted code here...it worked fine as you saw...last time I tried to post code here (with a source code box, of course)...it got mangled. So here goes nuttin'.
...much time passes...
Sorry Larry...I cannot seem to past any code either in a source code box or directly into the message without it being truncated. Any thoughts...I'll try a separate message and see what happens.
eyetech
Member
21 Points
49 Posts
Re: HTML source for testing gridview and detailsview controls
Jan 24, 2007 02:48 AM|LINK
Sorry, Larry....whenever I try to insert any source code, it is truncated at the first ConnectionString.