Friday, 11 July 2014

What are the different coding standards used in c# projects

There are 3 types of naming convention pascal,hungarian and Camel.



Pascal notation starts with all first letter of the word capital. For example

"Customercode" where you can see "C" letter capital in both the words.



Camel notation starts with all first letter capital except the first letter of 
the first word. For example "customerCode", you can see the first letter "c" 
small and the other "C" of the letter code capital.



Hungarian notation starts with first word as the datatype prefix. For instance "intCount","boolIsValie" 
etc. The first word describes the datatype lik int, bool etc.




Wednesday, 9 July 2014

How to read Xml File Using gridview in asp.net

How to read Xml File Using gridview in asp.net



source Of xml file
<?xml version="1.0" encoding="utf-8" ?>
<EmployeeInformation>

  <Employee>

    <sno>101</sno>

    <firstname>Pankaj </firstname>
      <lastname>Lohani</lastname>
      <address>hyderbad</address>

  </Employee>

  <Employee>

    <sno>102</sno>

    <firstname>sharath </firstname>
      <lastname>Lohani</lastname>
      <address>goa</address>

  </Employee>

  <Employee>

    <sno>103</sno>

    <firstname>rakesh </firstname>
      <lastname>Lohani</lastname>
      <address>delhi</address>

  </Employee>
  <Employee>
    <sno>105</sno>

    <firstname>rakkaj </firstname>
      <lastname>shiva</lastname>
      <address>hyderbad</address>

  </Employee>


</EmployeeInformation>


ASpx.page (Design view):
------------------------
    <asp:GridView ID="grddata1" runat="server">
    
    


    </asp:GridView>

Aspx.cs (code View File)


   protected voidPage_Load(object sender, EventArgs e)
    {

        var xmlfilepath = Server.MapPath("mydata.xml");
        DataSet dsemp = newDataSet();
        dsemp.ReadXml(xmlfilepath);
        grddata1.DataSource = dsemp.Tables[0].DefaultView;
        grddata1.DataBind();

    }





what is Inheritance in C#

Inheritance

Acquiring the properties of an existing class into a new class by establishing a parent–child relationship between classes is known as Inheritance.

The big advantage of inheritance is reusability of code:



  • using System;  
  • using System.Collections.Generic;  
  • using System.Linq;  
  • using System.Text;  
  • using System.Threading.Tasks;  
  •   
  • namespace InheritanceDemo  
  • {  
  •     class Parent  
  •     {  
  •         public void ParentMethod()  
  •         {  
  •             Console.WriteLine("this is parent method");  
  •         }  
  •     }  
  •     class child :Parent  
  •     {   
  •         public void childmethod()  
  •         {  
  •             Console.WriteLine("this is child method");  
  •         }  
  •         static void Main(string[] args)  
  •         {        
  •             child obj = new child();                            
  •             obj.childmethod();  
  •             obj.ParentMethod();  
  •             Console.ReadKey();  
  •         }  
  •     }  
  • }  
  • how to add image in Title bar

    Introduction

    This article shows how to add an image to the title bar of your website.
    Step:1
    create simple aspx page







    Step:2
    create icon that should be display in  title bar


    add icon to the  to the solution explore 
    Then write link in head section to display the icon in the title bar
     <link rel="Shortcut Icon" href="sky.jpg" />

    Output Of the Task






    Monday, 9 June 2014

    How to Changing color of rows or a cell in gridview control of ASP.Net,change GridView Row Background Color ,Changing Gridview row color based on value in that row

    Hai frnd this How to Changing color of rows or a cell in gridview control of ASP.Net

    In  Head Section take the css color's and use it in RowDataBound
    <head runat="server">
        <style type="text/css">
       
       
        .teal
        {
            background-color:Teal;
        }
        .green
        {
            background-color:Green;
        }
        </style>
        <title></title>

    -------------------------------------------------------------------------------------------------------
    ----------------------------------------------------------------------------------------------------

    Aspx.cs Page

    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
    {
        string cond = ConfigurationManager.ConnectionStrings["mydataconn"].ToString();
        SqlConnection con;
        SqlCommand cmd;
        SqlDataAdapter dap;
        DataSet ds;

        protected voidPage_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                grdview1.DataSource = myGridData();
                grdview1.DataBind();
            }

        }

        public DataSetmyGridData()
        {
            con = new SqlConnection(cond);
            cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "spdatadown";
            dap = new SqlDataAdapter(cmd);
            ds = new DataSet();
            dap.Fill(ds);
            return (ds);

           
        }
        protected voidgrdview1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (e.Row.Cells[1].Text.CompareTo("dora") == 0)
                {
                    e.Row.CssClass = "green";
                }
                else
                {
                    if (e.Row.Cells[1].Text.CompareTo("hello") == 0)
                    {
                        e.Row.CssClass = "teal";
                    }
                }
            }
        }
    }


    Wednesday, 4 June 2014

    binding a grid view for registration page ,ASP.net How to bind Datatable with Gridview Code 2014,how to bind gridview in asp.net c#

    Gridview Dynamic Binding the data:

    In this example i am inserting data to database and using grid we are going to display the data in the Front-End .
    here i am using fields as 
    sno, Firstname,Lastname,Emailid,Phoneno,Address
    where i am using sno as auto generate column ..
    2)when i am using Submit Button the data should be store in database and display in the Grid.



    Code For Design Page Of the example Aspx code

    <body style="background-color:Silver">
        <form id="form1" runat="server">
        <div align="center">
        <h2>Registration Page</h2>
        <table>
        <tr>
        <td>First Name</td>
        <td>:</td>
        <td><asp:TextBox ID="txtfirstname"runat="server"></asp:TextBox> </td>
       
        </tr>
         <tr>
        <td>Last Name</td>
        <td>:</td>
        <td><asp:TextBox ID="txtlastname"runat="server"></asp:TextBox> </td>
       
        </tr>
         <tr>
        <td>Email id</td>
        <td>:</td>
        <td><asp:TextBox ID="txtemailid"runat="server"></asp:TextBox> </td>
       
        </tr>
         <tr>
        <td>Phone No</td>
        <td>:</td>
        <td><asp:TextBox ID="txtphoneno"runat="server"></asp:TextBox> </td>
       
        </tr>
         <tr>
        <td>Address</td>
        <td>:</td>
        <td><asp:TextBox ID="txtaddress"runat="server"></asp:TextBox> </td>
       
        </tr>
        <tr>
       
        <td></td>
        <td></td>
        <td><asp:Button ID="btnsubmit"runat="server"Text="Submit"
                onclick="btnsubmit_Click"/></td>
        </tr>
       
        </table>
       
            <asp:GridView ID="GridView1"runat="server"AutoGenerateColumns="false">
            <Columns>
            <asp:TemplateField HeaderText="username">
            <ItemTemplate>
            <asp:Label ID="lblfstname"runat="server"Text='<%#Bind("firstname") %>' ></asp:Label>
           
            </ItemTemplate>
           
            </asp:TemplateField>
             <asp:TemplateField HeaderText="Lastname">
            <ItemTemplate>
            <asp:Label ID="lbllstname"runat="server"Text='<%#Bind("lastname") %>' ></asp:Label>
           
            </ItemTemplate>
           
            </asp:TemplateField>
             

             <asp:TemplateField HeaderText="Emailid">
            <ItemTemplate>
            <asp:Label ID="lblemail"runat="server"Text='<%#Bind("emailid") %>' ></asp:Label>
           
            </ItemTemplate>
           
            </asp:TemplateField>
             <asp:TemplateField HeaderText="Phoneno">
            <ItemTemplate>
            <asp:Label ID="lblphno"runat="server"Text='<%#Bind("Phoneno") %>' ></asp:Label>
           
            </ItemTemplate>

           
            </asp:TemplateField>

             <asp:TemplateField HeaderText="Delete">

            <ItemTemplate>
    <%--        <asp:Button ID="btndel" runat="server" Text="Delete" OnCommand="delete" CommandArgument='<%#Bind("sno")%>' />--%>
           <asp:ImageButton ID="btnlink"runat="server"Text="Delete"ImageUrl="~/icon_button_close.gif"OnCommand="delete"CommandArgument='<%#Bind("sno")%>' />
            </ItemTemplate>

           
            </asp:TemplateField>


           
          </Columns>

            </asp:GridView>

        </div>
       </form>
       </body>


    Next I am Using Aspx.cs page 

    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 samplegrid : System.Web.UI.Page
    {
        string conn = ConfigurationManager.ConnectionStrings["connent"].ToString();
        SqlConnection con;
        SqlCommand cmd;
        SqlDataAdapter dap;
        DataSet ds;

        codefile obj= new codefile();

        protected voidPage_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                gridbinddata();
            }
        }
        protected voidbtnsubmit_Click(object sender, EventArgs e)
        {
           

            obj.databind1(txtfirstname.Text,txtlastname.Text,txtemailid.Text,txtphoneno.Text,txtaddress.Text);
            gridbinddata();
        }

        private voidgridbinddata()
        {
            GridView1.DataSource = obj.gridbinddata();
            GridView1.DataBind();

           
        }
        public void delete(object sender, CommandEventArgse)
        {
              string str = e.CommandArgument.ToString();
              con = new SqlConnection(conn);
              cmd = new SqlCommand();

              cmd.Connection = con;
              cmd.CommandText = "spdeletedata";
              cmd.CommandType = CommandType.StoredProcedure;
              cmd.Parameters.AddWithValue("@spsno", str);

              con.Open();
              cmd.ExecuteNonQuery();
              con.Close();
              gridbinddata();
        }


     
       
    }



    Class File of aspx file or Ado.net file
    using System.Data;
    using System.Data.SqlClient;
    using System.Configuration;

    /// <summary>
    /// Summary description for codefile
    /// </summary>
    public class codefile
    {
        string conn = ConfigurationManager.ConnectionStrings["connent"].ToString();
        SqlConnection con;
        SqlCommand cmd;
        SqlDataAdapter dap;
        DataSet ds;
           public codefile()
           {
                  //
                  // TODO: Add constructor logic here
                  //
           }
        public voiddatabind1(string txtfirstname, string txtlastname, stringtxtemailid, string txtphoneno, string txtaddress)
        {
            con = new SqlConnection(conn);
            cmd = new SqlCommand();

            cmd.Connection = con;

            cmd.CommandText = "spregistrationfrom";
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@spfirstname", txtfirstname);
            cmd.Parameters.AddWithValue("@splastname", txtlastname);
            cmd.Parameters.AddWithValue("@spemailid", txtemailid);
            cmd.Parameters.AddWithValue("@spphoneno", txtphoneno);
            cmd.Parameters.AddWithValue("@spaddress", txtaddress);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
        }
        public DataSetgridbinddata()
        {
            con = new SqlConnection(conn);
            cmd = new SqlCommand();

            cmd.Connection = con;
            cmd.CommandText = "spgriddata";
            cmd.CommandType = CommandType.StoredProcedure;
            con.Open();
            dap = new SqlDataAdapter(cmd);
            ds = new DataSet();
            dap.Fill(ds);
            return (ds);
          
         
          
        }