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);
      
     
      
    }


   

Tuesday, 3 June 2014

Top 10 C# Interview Questions and Answers 2014,C# interview questions and answers | Sharath,important .NET interview Questions & Answers

1.what is importance of DOCTYPE in html?

<html>
<head>
<title>Title of the document</title>
</head>

<body>
The content of the document......
</body>

</html>
The <!DOCTYPE> declaration must be the very first thing in your HTML document, before the <html> tag.
The <!DOCTYPE> declaration is not an HTML tag; it is an instruction to the web browser about what version of HTML the page is written in.
In HTML 4.01, the <!DOCTYPE> declaration refers to a DTD, because HTML 4.01 was based on SGML. The DTD specifies the rules for the markup language, so that the browsers render the content correctly.
HTML5 is not based on SGML, and therefore does not require a reference to a DTD.
HTML (HyperText Markup Language) then I would suggest you use the HTML 4.01 Transitional declaration. It is much more forgiving for the beginner when performing HTML validation. You would also use this declaration if you know that your audience will not have a browser that supports CSS (Cascading Style Sheets).
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
This DOCTYPE declaration still allows elements and presentation attributes that should be in the stylesheet.
If you want to learn to code in preparation for the future but still not ready for XHTML then you would use the Strict declaration.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
With this declaration all presentation attributes are moved to the stylesheet.
!DOCTYPE
The identifier. It indicates to the user-agent that the enclosed information will define the type of document of the page.

2.what is frameset and frame?
The <frameset> tag is not supported in HTML5.
The <frameset> tag defines a frameset.
The <frameset> element holds one or more <frame> elements. Each <frame> element can hold a separate document.
The <frameset> element specifies HOW MANY columns or rows there will be in the frameset, and HOW MUCH percentage/pixels of space will occupy each of them.

Example:-
<frameset cols="25%,*,25%">
  <frame src="frame_a.htm">
  <frame src="frame_b.htm">
  <frame src="frame_c.htm">
</frameset>
The <frameset> Element:
  • The <frameset> tag replaces the <body> element in frameset documents.
  • The <frameset> tag defines how to divide the window into frames.
  • Each frameset defines a set of rows or columns. If you define frames by using rows then horizontal frames are created. If you define frames by using columns then vertical farmes are created.
  • The values of the rows/columns indicate the amount of screen area each row/column will occupy.
  • Each farme is indicated by <frame> tag and it defines what HTML document to put into the frame.



3.what are  form element in html  and  write each element syntax?
HTML forms are used to pass data to a server.
An HTML form can contain input elements like text fields, checkboxes, radio-buttons, submit buttons and more. A form can also contain select lists, textarea, fieldset, legend, and label elements. HTML elements in ASP.NET files are, by default, treated as text. To make these elements programmable, add a runat="server" attribute to the HTML element. This attribute indicates that the element should be treated as a server control.
Note: All HTML server controls must be within a <form> tag with the runat="server" attribute!

The <form> tag is used to create an HTML form:
<body>
    <form id="form1" runat="server">
<table   >

    <tr>
    <td><b>First Name</b></td>
    <td>:</td>
    <td>
        <asp:TextBox ID="TextBox1"runat="server"Height="18px"Width="166px"></asp:TextBox>
       &nbsp; &nbsp;
        <asp:RequiredFieldValidatorID="RequiredFieldValidator1"runat="server"
            ErrorMessage="*"ControlToValidate="TextBox1"ForeColor="Red"></asp:RequiredFieldValidator>
       
        <br />
       
        </td>
    
         </tr>

     <tr>

    <td><b>Last Name</b></td>
    <td>:</td>
    <td>
        <asp:TextBox ID="TextBox2"runat="server"Height="18px"Width="166px"  ></asp:TextBox>
       &nbsp; &nbsp;
        <asp:RequiredFieldValidatorID="RequiredFieldValidator2"runat="server"
            ErrorMessage="*"ControlToValidate="TextBox2"ForeColor="Red"></asp:RequiredFieldValidator>
       
        </td>
    </tr>
        <asp:DropDownList ID="DropDownList4"runat="server">
        </asp:DropDownList>
     <tr>

    <td><b>Education Qualification</b></td>
    <td>:</td>
    <td>
        <asp:DropDownList ID="DropDownList5"runat="server"Height="18px"Width="166px">
        <asp:ListItem>--Select--</asp:ListItem>
        <asp:ListItem>10Th Class</asp:ListItem>
        <asp:ListItem>Inter</asp:ListItem>
        <asp:ListItem>B.Tech</asp:ListItem>
        <asp:ListItem>B.Sc</asp:ListItem>
        <asp:ListItem>M.sc</asp:ListItem>
        <asp:ListItem>M.tech</asp:ListItem>
        <asp:ListItem>M.B.A</asp:ListItem>
        </asp:DropDownList>
       
          &nbsp; &nbsp;
        <asp:RequiredFieldValidatorID="RequiredFieldValidator3"runat="server"
            ErrorMessage="*"ControlToValidate="DropDownList5"ForeColor="Red"></asp:RequiredFieldValidator>
       
          </td>

    </tr>
</table>

4. create one function and call that function onto  button click?
<head runat="server">
    <title></title>
   <script>
       function myfun() {
           document.getElementById("demo").innerHTML = Date;
           }
    
        </script>
</head>
<body >
    <form id="form1" runat="server">
    <div align="center">
    <h1>Welcome to Javascript Language</h1>
    <p>Click the button to dispaly the date .</p>
    <p id="demo"></p>
    <button type="button"onclick="myfun()">Try it</button>
      
    </div>
    </form>
</body>



5.how to create array in javascript? dispaly records.

The Array object let's you store multiple values in a single variable.
Example for the arrays
var fruits = new Array( "apple", "orange", "mango" );
ordinal numbers to access and to set values inside an array as follows:
·  fruits[0] is the first element
·  fruits[1] is the second element
·  fruits[2] is the third element

<!DOCTYPE html>
<html>
<body>

<script>
var i;
var myworld = new Array();
myworld[0] = "sharath";
myworld[1] = "kumar    ";
myworld [2] = "reddy";

for (i=0;i<mycars.length;i++)
{
document.write(myworld [i] + "<br>");
}
</script>

</body>
</html>

Output:
Sharath
Kumar  

Reddy