Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 9th, 2012, 12:25 PM
Registered User
 
Join Date: Sep 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to display data from SQL as it was inserted

Hi Imar or other ladies and Gentlemen,

I need your help!!! I have been working on this problem for over two weeks and still have not figured out how to solve it. I appreciate that if anyone could help me!

I would like to create a news website and like to display the news headline and the news content from the sql data base directly. Everything seems fine, but the format of the displaying of the news content. Please see the following to learn what I did.

1. All News Display and Edit:

Page Title="Management-Beijington News Edit" Language="C#" MasterPageFile="~/MasterPages/Main.master" AutoEventWireup="true" CodeFile="NewsAddEddit.aspx.cs" Inherits="Management_NewsAddEddit" validateRequest="false" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpContent" Runat="Server">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="Id"
DataSourceID="SqlDataSource1" EnableModelValidation="False">
<Columns>
<asp:CommandField
ShowSelectButton="True" ShowEditButton="True" />
<asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False"
ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="Sumnary" HeaderText="Sumnary"
SortExpression="Sumnary" />
<asp:BoundField DataField="Body" HeaderText="Body" SortExpression="Body" />
<asp:BoundField DataField="AuthorId" HeaderText="AuthorId"
SortExpression="AuthorId" />
<asp:BoundField DataField="CategoryId" HeaderText="CategoryId"
SortExpression="CategoryId" />
<asp:BoundField DataField="CreateDateTime" HeaderText="CreateDateTime"
SortExpression="CreateDateTime" />
<asp:BoundField DataField="UpDateTime" HeaderText="UpDateTime"
SortExpression="UpDateTime" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:BeijingtonConnectionString %>"
DeleteCommand="DELETE FROM [News] WHERE [Id] = @original_Id AND [Title] = @original_Title AND [Sumnary] = @original_Sumnary AND [Body] = @original_Body AND [AuthorId] = @original_AuthorId AND [CategoryId] = @original_CategoryId AND [CreateDateTime] = @original_CreateDateTime AND [UpDateTime] = @original_UpDateTime"
InsertCommand="INSERT INTO [News] ([Title], [Sumnary], [Body], [AuthorId], [CategoryId], [CreateDateTime], [UpDateTime]) VALUES (@Title, @Sumnary, @Body, @AuthorId, @CategoryId, @CreateDateTime, @UpDateTime)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT * FROM [News]"
UpdateCommand="UPDATE [News] SET [Title] = @Title, [Sumnary] = @Sumnary, [Body] = @Body, [AuthorId] = @AuthorId, [CategoryId] = @CategoryId, [CreateDateTime] = @CreateDateTime, [UpDateTime] = @UpDateTime WHERE [Id] = @original_Id AND [Title] = @original_Title AND [Sumnary] = @original_Sumnary AND [Body] = @original_Body AND [AuthorId] = @original_AuthorId AND [CategoryId] = @original_CategoryId AND [CreateDateTime] = @original_CreateDateTime AND [UpDateTime] = @original_UpDateTime">
<DeleteParameters>
<asp:Parameter Name="original_Id" Type="Int32" />
<asp:Parameter Name="original_Title" Type="String" />
<asp:Parameter Name="original_Sumnary" Type="String" />
<asp:Parameter Name="original_Body" Type="String" />
<asp:Parameter Name="original_AuthorId" Type="Int32" />
<asp:Parameter Name="original_CategoryId" Type="Int32" />
<asp:Parameter Name="original_CreateDateTime" Type="DateTime" />
<asp:Parameter Name="original_UpDateTime" Type="DateTime" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Sumnary" Type="String" />
<asp:Parameter Name="Body" Type="String" />
<asp:Parameter Name="AuthorId" Type="Int32" />
<asp:Parameter Name="CategoryId" Type="Int32" />
<asp:Parameter Name="CreateDateTime" Type="DateTime" />
<asp:Parameter Name="UpDateTime" Type="DateTime" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Sumnary" Type="String" />
<asp:Parameter Name="Body" Type="String" />
<asp:Parameter Name="AuthorId" Type="Int32" />
<asp:Parameter Name="CategoryId" Type="Int32" />
<asp:Parameter Name="CreateDateTime" Type="DateTime" />
<asp:Parameter Name="UpDateTime" Type="DateTime" />
<asp:Parameter Name="original_Id" Type="Int32" />
<asp:Parameter Name="original_Title" Type="String" />
<asp:Parameter Name="original_Sumnary" Type="String" />
<asp:Parameter Name="original_Body" Type="String" />
<asp:Parameter Name="original_AuthorId" Type="Int32" />
<asp:Parameter Name="original_CategoryId" Type="Int32" />
<asp:Parameter Name="original_CreateDateTime" Type="DateTime" />
<asp:Parameter Name="original_UpDateTime" Type="DateTime" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:BeijingtonConnectionString %>"
DeleteCommand="DELETE FROM [News] WHERE [Id] = @Id"
InsertCommand="INSERT INTO [News] ([Title], [Sumnary], [Body], [AuthorId], [CategoryId], [CreateDateTime], [UpDateTime]) VALUES (@Title, @Sumnary, @Body, @AuthorId, @CategoryId, @CreateDateTime, @UpDateTime)"
SelectCommand="SELECT * FROM [News] WHERE ([Id] = @Id)"
UpdateCommand="UPDATE [News] SET [Title] = @Title, [Sumnary] = @Sumnary, [Body] = @Body, [AuthorId] = @AuthorId, [CategoryId] = @CategoryId, [CreateDateTime] = @CreateDateTime, [UpDateTime] = @UpDateTime WHERE [Id] = @Id">
<DeleteParameters>
<asp:Parameter Name="Id" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Sumnary" Type="String" />
<asp:Parameter Name="Body" Type="String" />
<asp:Parameter Name="AuthorId" Type="Int32" />
<asp:Parameter Name="CategoryId" Type="Int32" />
<asp:Parameter Name="CreateDateTime" Type="DateTime" />
<asp:Parameter Name="UpDateTime" Type="DateTime" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="Id"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Sumnary" Type="String" />
<asp:Parameter Name="Body" Type="String" />
<asp:Parameter Name="AuthorId" Type="Int32" />
<asp:Parameter Name="CategoryId" Type="Int32" />
<asp:Parameter Name="CreateDateTime" Type="DateTime" />
<asp:Parameter Name="UpDateTime" Type="DateTime" />
<asp:Parameter Name="Id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True"
AutoGenerateRows="False" DataKeyNames="Id" DataSourceID="SqlDataSource2"
DefaultMode="Edit" Height="650px" Width="100%" CellPadding="4"
ForeColor="#333333" GridLines="None" EnableModelValidation="False">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
<EditRowStyle BackColor="#999999" />
<FieldHeaderStyle Width="100px" BackColor="#E9ECF1" Font-Bold="True" />
<Fields>
<asp:TemplateField HeaderText="Id" InsertVisible="False" SortExpression="Id">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Id") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Title" SortExpression="Title">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Width="80%" Text='<%# Bind("Title") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Width="80%" Text='<%# Bind("Title") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Title") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sumnary" SortExpression="Sumnary">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" TextMode="MultiLine" Width="80%" Height="100px" Text='<%# Bind("Sumnary") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" TextMode="MultiLine" Width="80%" Height="100px" Text='<%# Bind("Sumnary") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Sumnary") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Body" SortExpression="Body">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" TextMode="MultiLine" Width="80%" Height="300px" Text='<%# Bind("Body") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" TextMode="MultiLine" Width="80%" Height="300px" Text='<%# Bind("Body") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("Body") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="AuthorId" SortExpression="AuthorId">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Width="80%" Text='<%# Bind("AuthorId") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Width="80%" Text='<%# Bind("AuthorId") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("AuthorId") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CategoryId" SortExpression="CategoryId">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Width="80%" Text='<%# Bind("CategoryId") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Width="80%" Text='<%# Bind("CategoryId") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("CategoryId") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CreateDateTime" SortExpression="CreateDateTime">
<EditItemTemplate>
<asp:TextBox ID="TextBox6" runat="server" Width="80%" Text='<%# Bind("CreateDateTime") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox6" runat="server" Width="80%" Text='<%# Bind("CreateDateTime") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("CreateDateTime") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="UpDateTime" SortExpression="UpDateTime">
<EditItemTemplate>
<asp:TextBox ID="TextBox7" runat="server" Width="80%" Text='<%# Bind("UpDateTime") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox7" runat="server" Width="80%" Text='<%# Bind("UpDateTime") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Bind("UpDateTime") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True"
CommandName="Update" Text="Update"></asp:LinkButton>
&nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
CommandName="Edit" Text="Edit"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Fields>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
</asp:DetailsView>
</asp:Content>

2. News Inserting:

<%@ Page Title="Management-Beijington News Insert" Language="C#" MasterPageFile="~/MasterPages/Main.master" AutoEventWireup="true" CodeFile="InsertNewNews.aspx.cs" Inherits="Management_InsertNewNews" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpContent" Runat="Server">
<br />
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataKeyNames="Id" DataSourceID="SqlDataSource1" DefaultMode="Insert"
Height="500px" Width="90%" CellPadding="4" ForeColor="#333333"
Align="center" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<CommandRowStyle BackColor="#C5BBAF" Font-Bold="True" />
<EditRowStyle BackColor="#7C6F57" />
<EmptyDataRowStyle Width="30%" />
<FieldHeaderStyle BackColor="#D0D0D0" Font-Bold="True" Width="100px" />
<Fields>
<asp:TemplateField HeaderText="Id" InsertVisible="False" SortExpression="Id">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Id") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Id") %>'></asp:Label>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Title" SortExpression="Title">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Title") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Title") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Title") %>'></asp:TextBox>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sumnary" SortExpression="Sumnary">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Sumnary") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox2" TextMode="MultiLine" width="100%" Height="200px" runat="server" Text='<%# Bind("Sumnary") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox2" TextMode="MultiLine" width="100%" Height="200px" runat="server" Text='<%# Bind("Sumnary") %>'></asp:TextBox>
</InsertItemTemplate>
<HeaderStyle HorizontalAlign="Left" VerticalAlign="Top" Wrap="False" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Body" SortExpression="Body">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("Body") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox3" TextMode="MultiLine" width="100%" Height="200px" runat="server" Text='<%# Bind("Body") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox3" TextMode="MultiLine" width="100%" Height="200px" runat="server" Text='<%# Bind("Body") %>'></asp:TextBox>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="AuthorId" SortExpression="AuthorId">
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("AuthorId") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("AuthorId") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("AuthorId") %>'></asp:TextBox>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CategoryId" SortExpression="CategoryId">
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("CategoryId") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("CategoryId") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("CategoryId") %>'></asp:TextBox>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CreateDateTime" SortExpression="CreateDateTime">
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("CreateDateTime") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("CreateDateTime") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("CreateDateTime") %>'></asp:TextBox>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="UpDateTime" SortExpression="UpDateTime">
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Bind("UpDateTime") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("UpDateTime") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("UpDateTime") %>'></asp:TextBox>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
CommandName="New" Text="New"></asp:LinkButton>
</ItemTemplate>
<InsertItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert"></asp:LinkButton>
&nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</InsertItemTemplate>
</asp:TemplateField>
</Fields>
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:BeijingtonConnectionString %>"
SelectCommand="SELECT * FROM [News]"
DeleteCommand="DELETE FROM [News] WHERE [Id] = @Id"
InsertCommand="INSERT INTO [News] ([Title], [Sumnary], [Body], [AuthorId], [CategoryId], [CreateDateTime], [UpDateTime]) VALUES (@Title, @Sumnary, @Body, @AuthorId, @CategoryId, @CreateDateTime, @UpDateTime)"
UpdateCommand="UPDATE [News] SET [Title] = @Title, [Sumnary] = @Sumnary, [Body] = @Body, [AuthorId] = @AuthorId, [CategoryId] = @CategoryId, [CreateDateTime] = @CreateDateTime, [UpDateTime] = @UpDateTime WHERE [Id] = @Id">
<DeleteParameters>
<asp:Parameter Name="Id" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Sumnary" Type="String" />
<asp:Parameter Name="Body" Type="String" />
<asp:Parameter Name="AuthorId" Type="Int32" />
<asp:Parameter Name="CategoryId" Type="Int32" />
<asp:Parameter Name="CreateDateTime" Type="DateTime" />
<asp:Parameter Name="UpDateTime" Type="DateTime" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Sumnary" Type="String" />
<asp:Parameter Name="Body" Type="String" />
<asp:Parameter Name="AuthorId" Type="Int32" />
<asp:Parameter Name="CategoryId" Type="Int32" />
<asp:Parameter Name="CreateDateTime" Type="DateTime" />
<asp:Parameter Name="UpDateTime" Type="DateTime" />
<asp:Parameter Name="Id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<br />
</asp:Content>

3. News Headline Display:

Page Title="Beijington News Headline" Language="C#" MasterPageFile="~/MasterPages/Main.master" AutoEventWireup="true" CodeFile="NewsHeadline.aspx.cs" Inherits="Management_NewsHeadline" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" runat="server" contentplaceholderid="cpContent">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="Id" DataSourceID="SqlDataSource1" GridLines="None"
ShowHeader="False">
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="Id"
DataNavigateUrlFormatString="NewsDisplay.aspx?Id={ 0}" DataTextField="Title"
HeaderText="Title" Target="_blank" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:BeijingtonConnectionString %>"
SelectCommand="SELECT [Id], [Title] FROM [News]"></asp:SqlDataSource>
</asp:Content>

4. News Display( show the main body of the content):

<%@ Page Title="Beijington News Display" Language="C#" MasterPageFile="~/MasterPages/Main.master" AutoEventWireup="true" CodeFile="NewsDisplay.aspx.cs" Inherits="Management_NewsDisplay" %>


<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>


<%@ Register src="../Controls/Comments.ascx" tagname="Comments" tagprefix="uc1" %>


<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>

<asp:Content ID="Content2" runat="server" contentplaceholderid="cpContent">

<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataSourceID="SqlDataSource1" GridLines="None" Height="300px"
HorizontalAlign="Left" Width="700px" AllowPaging="True">
<Fields>
<asp:TemplateField HeaderText="Body" ShowHeader="False" SortExpression="Body">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Body") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Body") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Body") %>'></asp:Label>
</ItemTemplate>
<ItemStyle VerticalAlign="Top" />
</asp:TemplateField>
</Fields>
</asp:DetailsView>
<br />
<span />
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:BeijingtonConnectionString %>"
SelectCommand="SELECT [Body] FROM [News] WHERE ([Id] = @Id)">
<SelectParameters>
<asp:QueryStringParameter Name="Id" QueryStringField="Id" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>



</asp:Content>

My question is: How to display the text in paragraph, keeping the style ect..
By the way, I am not good in coding. Please tell me how write the code to convert the sql data (just one column of the data table) to a web page Html. Please tell me in details as more specific as possible.

I am looking forward to hearing from you as soon as possible!

Thank you very much!

Best Regards,

Guanghua Wu

From Beijing, China
 
Old September 9th, 2012, 02:52 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Is this related to my book Beginning ASP.NET 4 in C# and VB? If so, can you specify chapter and page numbers of the exercise you're working with? If not, a better place to post this is in the general ASP.NET 4 category: http://p2p.wrox.com/asp-net-4-539/ That way, others can join and learn from the discussion as well.

That said, I don't understand what the problem is. I see *a lot* of code, but you're not really describing the problem or your desired output.

Quote:
By the way, I am not good in coding. Please tell me how write the code to convert the sql data (just one column of the data table) to a web page Html. Please tell me in details as more specific as possible.
If that's the case, make sure you go through the database related chapters (12-15). They cover this in great detail.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old September 10th, 2012, 02:12 PM
Registered User
 
Join Date: Sep 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Thank you

Hi there,

Thank you so much for your quick response! I am sorry that I have not explained my question clearly.

Yes, I am reader of your book"Beginning ASP.NET" and a follower of you. Your book is the first book I read relating to Website Creation. I am a beginner. I have bought almost all the books coving the topics on ASP.NET including the Professional ASP.NET 4 published by Wrox. For me, your book is the best for beginners like me! After I read your book, I also bought a Visual Studio Professional. It cost me a lot!

I will post a new thread to explain my question as clearly as I can.

Regards,

Guanghua Wu





Similar Threads
Thread Thread Starter Forum Replies Last Post
ODBC in Perl to display SQL data? buddyz Perl 1 March 16th, 2007 10:51 AM
how to avoid edit of inserted data in Excel? kotaiah Excel VBA 3 September 14th, 2006 01:49 AM
Display text data in textarea from SQL query palvin Classic ASP Databases 0 November 29th, 2005 05:44 PM
Getting ID from inserted data in Access chrscote Classic ASP Databases 6 June 23rd, 2005 02:09 PM
Data to be inserted into the database countmedream BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 0 November 2nd, 2004 03:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.