Tuesday, 26 June 2012

Display records as First-Next-Previous-Last in a Textboxes and Show record in a Gridview?


Here i am first time Explain widow based programming that how to Display records as First-Next-Previous-Last in a Textboxes and Show record in a Gridview?




Here Code of window application....

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Data.SqlClient;
using System.IO;
namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        DataSet ds;
        SqlDataAdapter da;
        SqlConnection con;
        int i = 0;
       
        private void Form1_Load(object sender, EventArgs e)
        {
            con = new SqlConnection("Data Source=PANKAJ-PC;Initial Catalog=pankurani;Integrated Security=True");
            con.Open();
             da = new SqlDataAdapter("select * from emp1", con);
            SqlCommandBuilder buil=new SqlCommandBuilder(da);
            ds = new DataSet();
            da.Fill(ds, "emp1");
            dataGridView1.DataSource = ds.Tables["emp1"];
           
        }
        private void b1_Click(object sender, EventArgs e)
        {
            if (ds.Tables[0].Rows.Count > 0) {
                i = 0;
                textBox1.Text = ds.Tables[0].Rows[i]["ID"].ToString();
                textBox2.Text = ds.Tables[0].Rows[i]["empname"].ToString();
                textBox3.Text = ds.Tables[0].Rows[i]["salary"].ToString(); }
        }
        private void b2_Click(object sender, EventArgs e)
        {
            i = ds.Tables[0].Rows.Count - 1;
            textBox1.Text = ds.Tables[0].Rows[i]["ID"].ToString();
            textBox2.Text = ds.Tables[0].Rows[i]["empname"].ToString();
            textBox3.Text = ds.Tables[0].Rows[i]["salary"].ToString();
        }
        private void b3_Click(object sender, EventArgs e)
        {
            if (i < ds.Tables[0].Rows.Count - 1) { i++;
                textBox1.Text = ds.Tables[0].Rows[i]["ID"].ToString();
                textBox2.Text = ds.Tables[0].Rows[i]["empname"].ToString();
                textBox3.Text = ds.Tables[0].Rows[i]["salary"].ToString();
            }
            else {
            }
        }
        private void b4_Click(object sender, EventArgs e)
        {
            if (i == ds.Tables[0].Rows.Count - 1 || i !=0)
            { 
                i--;
                textBox1.Text = ds.Tables[0].Rows[i]["ID"].ToString(); 
                textBox2.Text = ds.Tables[0].Rows[i]["empname"].ToString(); 
                textBox3.Text = ds.Tables[0].Rows[i]["salary"].ToString(); 
            }     
            else  
            {    
            } 
        }
        }
      
    }




      Thursday, 14 June 2012

      How To Fetch Record in textbox When Select particular ID in Drop downlist?


      Here we will learn how to How To Fetch Record in textbox When Select particular ID in Drop- downlist in asp.net? We can easily develop this application . first we will make a dropdownlist and write code dropdownclick event and use dropdownlist method write code Please try and learn.

      Create Database name- Dep
      Table name-panku
      Field-Id---int(primary Key)
               Name(varchar(50))
               Class(varchar(50)
      Here design Default.aspx asp.net page ....



      <table class="style1" style="background-color: #454545; color: #FFFFFF">
          <tr>
              <td class="style3" colspan="2">
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; How To Fetch
                  Record in textbox When Select particular ID in Drop downlist</td>
          </tr>
          <tr>
              <td class="style3">
                  <strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  Select Id</strong></td>
              <td>
                  <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
                      onselectedindexchanged="DropDownList1_SelectedIndexChanged" Width="157px">
                  </asp:DropDownList>
              </td>
          </tr>
          <tr>
              <td class="style3">
                  <strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  Name</strong></td>
              <td>
                  <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
              </td>
          </tr>
          <tr>
              <td class="style2">
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  Class</td>
              <td>
                  <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
              </td>
          </tr>
          <tr>
              <td class="style2">
                  &nbsp;</td>
              <td>
                  &nbsp;</td>
          </tr>
      </table>


      Here we will keep code in Default.aspx.cs  asp.net page ....

      Default.aspx.cs
      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      using System.Web.UI;
      using System.Web.UI.WebControls;
      using System.Data;
      using System.Data.SqlClient;
      using System.Configuration;

      public partial class _Default : System.Web.UI.Page
      {
          SqlConnection conn;
          protected void Page_Load(object sender, EventArgs e)
          {
              if (!Page.IsPostBack)
              {
                 
                  FillDropDownList1();

                
              }
          }
          private void FillDropDownList1()
          {
             
              conn= new SqlConnection(@"Data Source=PANKAJ-PC;Initial Catalog=dep;Integrated Security=True");
              SqlCommand cmd = new SqlCommand("select [ID] from panku", conn);
              SqlDataAdapter sda = new SqlDataAdapter(cmd);
              DataSet ds = new DataSet();
              sda.Fill(ds);
              DropDownList1.DataSource = ds;

              DropDownList1.DataTextField = "ID";
              DropDownList1.DataValueField = "ID";
              DropDownList1.DataBind();
              DropDownList1.Items.Insert(0, new ListItem("---Select---", "0"));
          }
          protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
          {
              ID = DropDownList1.SelectedItem.Value;
             conn = new SqlConnection(@"Data Source=PANKAJ-PC;Initial Catalog=dep;Integrated Security=True");
              string sqlStatement = string.Empty;
              SqlDataReader dr;
              sqlStatement = "select * from panku where [ID]='" + ID + "'";
              conn.Open();
              SqlCommand cmd = new SqlCommand(sqlStatement, conn);
              cmd.Connection = conn;
              dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
              int intRecordCount = 0;
              while (dr.Read())
              {
                  intRecordCount = intRecordCount + 1;
                  TextBox1.Text = dr.GetString(intRecordCount);
                  intRecordCount = intRecordCount + 1;
                  TextBox2.Text = dr.GetString(intRecordCount);
                 

              }
              dr.NextResult();
          }
      }
       Now Please Try this ...

      Thursday, 7 June 2012

      Chatting Using with Web application in asp.net with c#.

      Here we will learn how to create chat room for chatting in web application in asp.net with c#  we can easily chat the application  on our requirements.  

      Here design Default2.aspx page in asp.net .....
      <div>
          <table width="100%">
          <tr>
          <td width="15%">
          <img src="121020111216.jpg" style="width: 167px; height: 105px" />
          </td>
          <td valign="top">
          <span style="font-size:11pt; color:#003366; font-family:Trebuchet MS">
          <strong>Pankaj Chat
          <br />

          <br />

          <img src="pr.png" style="width: 152px"/></strong>
         
         
          </span>
          </td>
          </tr>
          <tr>
          <td colspan="3">
              Show Message<span style=" font-size:10pt; color:#003333; font-family:Verdana"><strong>&nbsp;
         
         
          </strong></span>
         
         
          </td>
         
          </tr>
          <tr>
          <td colspan="3">
              <asp:TextBox ID="txtmsg" runat="server" Height="180px" TextMode="MultiLine"
                  Width="240px"></asp:TextBox></td>
          </tr>
         
             <tr>
                 <td colspan="2">
                     Name<span style="font-size: 10pt; font-family: Verdana"><strong>:</strong></span><asp:TextBox
                         ID="txtname" runat="server" Font-Names="MS Reference Sans Serif"
                         Width="158px"></asp:TextBox></td>
          </tr>
         
             <tr>
                 <td colspan="2" valign="top">
                     &nbsp; &nbsp;Message Type:<asp:TextBox
                         ID="txtmess" runat="server" Height="60px" TextMode="MultiLine"
                         Width="154px"></asp:TextBox></td>
          </tr>
              <tr>
                  <td colspan="2" style="height: 35px">
                      &nbsp; &nbsp; &nbsp; &nbsp;<img src="pr.png" style="height: 29px"/>
                      &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                      <asp:ImageButton ID="ImageButton1" runat="server" Height="36px" ImageUrl="~/send_button.png"
                          Width="64px" onclick="ImageButton1_Click" /></td>
              </tr>
         
          </table>
          </div>
      Default2.aspx.cs
      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      using System.Web.UI;
      using System.Web.UI.WebControls;

      public partial class Default2 : System.Web.UI.Page
      {
          protected void Page_Load(object sender, EventArgs e)
          {
              string msg = (string)Application["msg"];

              txtmsg.Text = msg;
          }
          protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
          {
              string name = txtname.Text;

              string message = txtmess.Text;

              string mymessage = name + "::" + message;

              //Appending the User Entered Data To Application["msg"] object
              Application["msg"] = Application["msg"] + mymessage + Environment.NewLine;

              //Finally Dispaling on the Chat Content
              txtmsg.Text = Application["msg"].ToString();

              txtmess.Text = "";
          }
      }
      Default.aspx
      <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
      <script language="javascript" type="text/javascript">

          function panku() {
            var newwin=window.open("Default2.aspx", 'method_desc', 'width=300, height=500, left=350,, top=120')
          }

      </script>
      </asp:Content>
      <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
              <div >
          <asp:Button ID="b1" runat="server" Text=" Start chat"
                  OnClientClick="javascript:panku();" Height="23px" BackColor="#6600CC"
                  BorderStyle="Groove" ForeColor="White" />
          </div>
      </asp:Content>


      What is ASP.NET? Components of ASP.NET

      ASP.Net Definition -It is used for creating web-based applications.ASP.Net is a web development platform provided by Microsoft. ASP.NET i...