For more information visit my site: New AspDotNet Concepts
Hai Friend Today I developed task using Repeater Control ,where user comment on the webpage the data is displayed below with the time.
Aspx code
- <body style="background-image: url('webdesign_1338484318_44.jpg')">
- <form id="form1" runat="server">
- <div align="center">
- <asp:Label ID="lblresults" runat="server" Text="" ForeColor="Red"></asp:Label>
-
- <h2 >Contact US</h2>
- <table>
- <tr>
- <td><b class="h1">Enter Name</b></td>
- <td>:</td>
- <td><asp:TextBox ID="txtname" runat="server" CssClass="h1" ToolTip="Enter Your Name"></asp:TextBox></td>
- </tr>
- <tr>
- <td><b class="h1">Enter Subject</b></td>
- <td>:</td>
- <td><asp:TextBox ID="txtsubject" runat="server" CssClass="h1" ToolTip="Enter Your Name"></asp:TextBox></td>
- </tr>
- <tr>
- <td><b class="h1">Enter Comments</b></td>
- <td>:</td>
- <td><asp:TextBox CssClass="h1" ID="txtcomments" runat="server" TextMode="MultiLine"
- ToolTip="Enter Your Name" Height="80px" style="margin-left: 0px"
- Width="212px"></asp:TextBox></td>
- </tr>
- <tr>
- <td>
-
- </td>
- <td></td>
- <td>
- <br />
- <asp:Button ID="btnsubmit" runat="server" Text="Submit" onclick="btnsubmit_Click" />
- </td>
- </tr>
- </table >
- </div>
- <div align="center">
- <asp:Repeater ID="repeaterdata" runat="server" >
-
-
- <HeaderTemplate>
- <table align="center">
- <tr>
- <td> <h3 class="h1">Comments</h3>
- </td>
- </tr>
- </table>
- </HeaderTemplate>
- <ItemTemplate>
- <table style="border=1px" >
- <tr>
- <td>
- <table border="1px" style="background-color:Orange">
- <table style="background-color:Orange" >
- <tr>
- <td>
- <asp:Label BackColor="Orange" ID="Label1" runat="server" Text='<%#Bind("sno") %>'></asp:Label> )
- <b>Subject</b> <asp:Label BackColor="Orange"ID="lblsubject"runat="server"Text='<%#Bind("subject") %>'></asp:Label> </td>
- </tr>
- </table>
-
- </td>
- </tr>
- <tr>
- <td>
- <asp:Label ID="lblcomments" runat="server" Text='<%#Bind("comments") %>'></asp:Label>
- </td>
- </tr>
- <tr>
- <td>
-
- <table border="1px" style="background-color:Green">
-
- <tr>
- <td>
- Post By <asp:Label ID="lblpost"runat="server"Text='<%#Bind("username") %>'></asp:Label>
- </td>
-
- <td>
- Create Date : <asp:Label ID="lbldate" runat="server" Text='<%#Bind("postedDate") %>'></asp:Label>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
-
- </ItemTemplate>
- </asp:Repeater>
- </div>
- </form>
- </body>
Aspx code file
- using System.Data;
- using System.Data.SqlClient;
- using System.Configuration;
-
- public partial class WebBasedComments: System.Web.UI.Page
- {
- string connentionconfig = ConfigurationManager.ConnectionStrings["mydataconfig"].ToString();
- SqlConnection sqlcon = null;
- SqlCommand sqlcmd = null;
- DataSet ds = null;
- SqlDataAdapter sqldap = null;
- protected voidPage_Load(object sender, EventArgs e)
- {
- if(!Page.IsPostBack)
- {
- datarepeater();
-
- }}
- public voiddatarepeater()
- {
- sqlcon = new SqlConnection(connentionconfig);
- sqlcmd = new SqlCommand();
-
- sqlcmd.Connection = sqlcon;
- sqlcmd.CommandType = CommandType.StoredProcedure;
- sqlcmd.CommandText = "myinsertmahesh";
- sqldap = new SqlDataAdapter(sqlcmd);
- ds = new DataSet();
- sqldap.Fill(ds);
- repeaterdata.DataSource=ds;
- repeaterdata.DataBind();
- }
-
- protected voidbtnsubmit_Click(object sender, EventArgs e)
- {
- submiddata(txtname.Text, txtsubject.Text, txtcomments.Text);
- datarepeater();
-
- lblresults.Text = "data Inserted Sucessfully";
- }
-
- public voidsubmiddata(string username, string subject, stringcomments)
- {
- sqlcon = new SqlConnection(connentionconfig);
- sqlcmd = new SqlCommand();
- sqlcon.Open();
- sqlcmd.Connection = sqlcon;
- sqlcmd.CommandType = CommandType.StoredProcedure;
- sqlcmd.CommandText = "mydatainsert";
- sqlcmd.Parameters.AddWithValue("@spusername",username);
-
- sqlcmd.Parameters.AddWithValue("@spsubject",subject);
-
- sqlcmd.Parameters.AddWithValue("@spcomments",comments);
- sqlcmd.Parameters.AddWithValue("@spdatetime",DateTime.Now);
- sqlcmd.ExecuteNonQuery();
- sqlcon.Close();
-
- }
-
- }
DataBase Queries - create database skyworld
- use skyworld
-
- create table repeater(sno int identity(1,1),username varchar(30),subject varchar(max),comments varchar(30),postedDate datetime)
-
- select * from repeater
- create procedure mydatainsert
- (@spusername varchar(30),@spsubject varchar(max),@spcomments varchar(30),@spdatetime varchar(30))
- as
- begin
- insert into repeater values(@spusername,@spsubject,@spcomments,@spdatetime)
- end
- go
-
- create procedure myinsertmahesh
- as
- begin
- select * from repeater order by sno desc
- end
- go