Write news script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Smurfas
    New Member
    • Jul 2008
    • 30

    Write news script

    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
    Code:
     protected void Button1_Click(object sender, EventArgs e)
        {
            
            if (NewsName.Text == "") { LaukasTuscias.Text = "Irasykit naujienos varda"; }  //Please write News Name
            if (ShortNews.Text == "") { LaukasTuscias.Text = "Irasykit trumpa naujienos versija"; } //Please write Short news 
            if (FullNews.Text == "") { LaukasTuscias.Text = "Irasykit pilna versija"; }  //Please write Full news
    
            if (NewsName.Text == "" || ShortNews.Text == "" || FullNews.Text == "") { dbKlaida.Text = "Klaida, palikot tusciu laukeliu"; } //Error, blank is empty
            else
            {
                SqlConnection conn;
                SqlCommand comm;
    
                String connectionString =
                ConfigurationManager.ConnectionStrings[
                "Dorknozzle"].ConnectionString;
                conn = new SqlConnection(connectionString);
    
                comm = new SqlCommand(
                "INSERT INTO News (NameNews, ShortNews, FullNews, Author) " +
                "VALUES (@NameNews, @ShortNews, @FullNews, @Author)", conn);
    
                comm.Parameters.Add("@Author",
                System.Data.SqlDbType.NChar, 20);
                comm.Parameters["@Author"].Value = "Dzimis";
    
                comm.Parameters.Add("@NameNews",
                System.Data.SqlDbType.Text);
                comm.Parameters["@NameNews"].Value = NewsName.Text;
    
                comm.Parameters.Add("@ShortNews",
                System.Data.SqlDbType.Text);
                comm.Parameters["@ShortNews"].Value = ShortNews.Text;
    
                comm.Parameters.Add("@FullNews",
                System.Data.SqlDbType.Text);
                comm.Parameters["@FullNews"].Value = FullNews.Text;
    
                try
                {
                    conn.Open();
                    comm.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    dbKlaida.Text = "Neprisijunge prie duomenu bazes!<br />" + ex.Message; //Error, don't connect to DB
                }
                finally
                {
                    conn.Close();
                }
                dbKlaida.Text = "Duomenys issiusti";  //All Ok
                NewsName.Text = ""; //Clear TextBox
                ShortNews.Text = "";
                FullNews.Text = "";
            }
    
            
        }
    --------------------------------------------------------------------------------
    Show News:
    --------------------------------------------------------------------------------
    Code:
     protected void Page_Load(object sender, EventArgs e)
        {
    
            SqlConnection conn;
            SqlCommand comm;
            SqlDataReader reader;
            String connectionString = ConfigurationManager.ConnectionStrings["Dorknozzle"].ConnectionString;
    
            conn = new SqlConnection(connectionString);
            comm = new SqlCommand("SELECT Author, ShortNews, ID FROM News", conn);
    
            try
            {
                conn.Open();
                reader = comm.ExecuteReader();
                NewsList.DataSource = reader;
                NewsList.DataBind();
    
                reader.Close();
            }
            catch (Exception ex)
            {
                dbKlaida.Text = "Klaida, Neprisijungė prie Duomenų bazės!<br />" + ex.Message; //Error
            }
            finally
            {
                conn.Close();
            } 
        }
    ----------------------------
    Code:
    <body>
        <form id="form1" runat="server">
              <asp:DataList id="NewsList" runat="server">
    <ItemTemplate>
    Author: <strong><%#Eval("Author")%></strong><br />
    Short News: <strong><%#Eval("ShortNews")%></strong><br />
    <a><center>Read Full News</center></a>
    </ItemTemplate>
    <SeparatorTemplate>
    <hr />
    </SeparatorTemplate>
    <SelectedItemStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
    <AlternatingItemStyle BackColor="White" />
    <ItemStyle BackColor="#E3EAEB" />
    <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
    </asp:DataList>
         <asp:Label ID="dbKlaida" runat="server" Text=""></asp:Label>
     
        </form>
    </body>
    Thanks
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    Edit:
    Can you please clarify your question?

    Comment

    • Smurfas
      New Member
      • Jul 2008
      • 30

      #3
      Originally posted by insertAlias
      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:



      Comment

      • Smurfas
        New Member
        • Jul 2008
        • 30

        #4
        Still don't understand my problam?

        Comment

        • Curtis Rutland
          Recognized Expert Specialist
          • Apr 2008
          • 3264

          #5
          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.

          Comment

          • RedSon
            Recognized Expert Expert
            • Jan 2007
            • 4980

            #6
            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...

            Comment

            • RedSon
              Recognized Expert Expert
              • Jan 2007
              • 4980

              #7
              Originally posted by RedSon
              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:
              Code:
              <%#Eval("ShortNews")%>
              And create the proper <a> </a> tag to get the link.

              Comment

              • Smurfas
                New Member
                • Jul 2008
                • 30

                #8
                Originally posted by insertAlias
                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
                Code:
                <asp:HyperLink ID="FullNewsHyperLink" runat="server" NavigateUrl='<%# Eval("NewsId", Server.HtmlDecode("~/Default.aspx?NewsId={0}")) %>' Text="Full News" />

                Comment

                Working...