469,950 Members | 2,314 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,950 developers. It's quick & easy.

Write news script

30
Hi, I write News Script:
Write news skript, but how maket that - Whent I push "Read Full News" show full news? Some like that: http://blogs.msdn.com/


Sorry, for bad English


My script
Expand|Select|Wrap|Line Numbers
  1.  protected void Button1_Click(object sender, EventArgs e)
  2.     {
  3.  
  4.         if (NewsName.Text == "") { LaukasTuscias.Text = "Irasykit naujienos varda"; }  //Please write News Name
  5.         if (ShortNews.Text == "") { LaukasTuscias.Text = "Irasykit trumpa naujienos versija"; } //Please write Short news 
  6.         if (FullNews.Text == "") { LaukasTuscias.Text = "Irasykit pilna versija"; }  //Please write Full news
  7.  
  8.         if (NewsName.Text == "" || ShortNews.Text == "" || FullNews.Text == "") { dbKlaida.Text = "Klaida, palikot tusciu laukeliu"; } //Error, blank is empty
  9.         else
  10.         {
  11.             SqlConnection conn;
  12.             SqlCommand comm;
  13.  
  14.             String connectionString =
  15.             ConfigurationManager.ConnectionStrings[
  16.             "Dorknozzle"].ConnectionString;
  17.             conn = new SqlConnection(connectionString);
  18.  
  19.             comm = new SqlCommand(
  20.             "INSERT INTO News (NameNews, ShortNews, FullNews, Author) " +
  21.             "VALUES (@NameNews, @ShortNews, @FullNews, @Author)", conn);
  22.  
  23.             comm.Parameters.Add("@Author",
  24.             System.Data.SqlDbType.NChar, 20);
  25.             comm.Parameters["@Author"].Value = "Dzimis";
  26.  
  27.             comm.Parameters.Add("@NameNews",
  28.             System.Data.SqlDbType.Text);
  29.             comm.Parameters["@NameNews"].Value = NewsName.Text;
  30.  
  31.             comm.Parameters.Add("@ShortNews",
  32.             System.Data.SqlDbType.Text);
  33.             comm.Parameters["@ShortNews"].Value = ShortNews.Text;
  34.  
  35.             comm.Parameters.Add("@FullNews",
  36.             System.Data.SqlDbType.Text);
  37.             comm.Parameters["@FullNews"].Value = FullNews.Text;
  38.  
  39.             try
  40.             {
  41.                 conn.Open();
  42.                 comm.ExecuteNonQuery();
  43.             }
  44.             catch (Exception ex)
  45.             {
  46.                 dbKlaida.Text = "Neprisijunge prie duomenu bazes!<br />" + ex.Message; //Error, don't connect to DB
  47.             }
  48.             finally
  49.             {
  50.                 conn.Close();
  51.             }
  52.             dbKlaida.Text = "Duomenys issiusti";  //All Ok
  53.             NewsName.Text = ""; //Clear TextBox
  54.             ShortNews.Text = "";
  55.             FullNews.Text = "";
  56.         }
  57.  
  58.  
  59.     }
  60.  
--------------------------------------------------------------------------------
Show News:
--------------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1.  protected void Page_Load(object sender, EventArgs e)
  2.     {
  3.  
  4.         SqlConnection conn;
  5.         SqlCommand comm;
  6.         SqlDataReader reader;
  7.         String connectionString = ConfigurationManager.ConnectionStrings["Dorknozzle"].ConnectionString;
  8.  
  9.         conn = new SqlConnection(connectionString);
  10.         comm = new SqlCommand("SELECT Author, ShortNews, ID FROM News", conn);
  11.  
  12.         try
  13.         {
  14.             conn.Open();
  15.             reader = comm.ExecuteReader();
  16.             NewsList.DataSource = reader;
  17.             NewsList.DataBind();
  18.  
  19.             reader.Close();
  20.         }
  21.         catch (Exception ex)
  22.         {
  23.             dbKlaida.Text = "Klaida, Neprisijungė prie Duomenų bazės!<br />" + ex.Message; //Error
  24.         }
  25.         finally
  26.         {
  27.             conn.Close();
  28.         } 
  29.     }
  30.  
----------------------------
Expand|Select|Wrap|Line Numbers
  1. <body>
  2.     <form id="form1" runat="server">
  3.           <asp:DataList id="NewsList" runat="server">
  4. <ItemTemplate>
  5. Author: <strong><%#Eval("Author")%></strong><br />
  6. Short News: <strong><%#Eval("ShortNews")%></strong><br />
  7. <a><center>Read Full News</center></a>
  8. </ItemTemplate>
  9. <SeparatorTemplate>
  10. <hr />
  11. </SeparatorTemplate>
  12. <SelectedItemStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
  13. <AlternatingItemStyle BackColor="White" />
  14. <ItemStyle BackColor="#E3EAEB" />
  15. <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
  16. </asp:DataList>
  17.      <asp:Label ID="dbKlaida" runat="server" Text=""></asp:Label>
  18.  
  19.     </form>
  20. </body>
  21.  
  22.  
Thanks
Aug 13 '08 #1
7 1430
Curtis Rutland
3,256 Expert 2GB
Edit:
Can you please clarify your question?
Aug 13 '08 #2
Smurfas
30
Edit:
Can you please clarify your question?
Sorry, I bad speak English...
I need sample News scriptas(Write news in my page)

I have pictures, I hope now youn understand:




http://smurfas.puslapiai.lt/newsScript.JPG
Aug 13 '08 #3
Smurfas
30
Still don't understand my problam?
Aug 14 '08 #4
Curtis Rutland
3,256 Expert 2GB
Hmm, I think I understand the question, but it is a pretty general one.

What you are doing is basically a "blog." Try searching for some sample ASP.NET Blogs to see if you find anything.
Aug 14 '08 #5
RedSon
5,000 Expert 4TB
No I think the question is, how can he render the html such that the "read full news" link is an actual URL to the page that has the full news story...
Aug 14 '08 #6
RedSon
5,000 Expert 4TB
No I think the question is, how can he render the html such that the "read full news" link is an actual URL to the page that has the full news story...
I would imagine you can do something similar to this item:
Expand|Select|Wrap|Line Numbers
  1. <%#Eval("ShortNews")%>
  2.  
And create the proper <a> </a> tag to get the link.
Aug 14 '08 #7
Smurfas
30
Hmm, I think I understand the question, but it is a pretty general one.

What you are doing is basically a "blog." Try searching for some sample ASP.NET Blogs to see if you find anything.

Yes, I need simple Blog sample or guest book without xml.

I some have, what i need, but i need full example
Expand|Select|Wrap|Line Numbers
  1. <asp:HyperLink ID="FullNewsHyperLink" runat="server" NavigateUrl='<%# Eval("NewsId", Server.HtmlDecode("~/Default.aspx?NewsId={0}")) %>' Text="Full News" /> 
Aug 14 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Bob Murdoch | last post: by
6 posts views Thread by Mike Daniel | last post: by
3 posts views Thread by Ike | last post: by
8 posts views Thread by Ben | last post: by
2 posts views Thread by bissatch | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.