Tuesday, 26 April 2011

Add new row at runtime in Grid View.

Hello,
     If you want to add new row in grid view at run time using ASP.NET(C# ) then firstly you need to have labels, textbox in your grid view.

Here is the image of that grid view on which we are going to work...

The Source code for creating grid view is like....

<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
            AllowSorting="True" AutoGenerateColumns="False" BackColor="White"
            BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3"
            onpageindexchanging="GridView1_PageIndexChanging"
            onrowcancelingedit="GridView1_RowCancelingEdit"
            onrowdeleting="GridView1_RowDeleting" onrowediting="GridView1_RowEditing"
            onrowupdating="GridView1_RowUpdating" onsorting="GridView1_Sorting"
            PageSize="5" ShowFooter="True" ForeColor="Black" GridLines="Vertical">
            <AlternatingRowStyle BackColor="#CCCCCC" />
            <Columns>
                <asp:TemplateField HeaderText="ID" SortExpression="ID">
                    <EditItemTemplate>
                        <asp:Label ID="Label4" runat="server" Text='<%# Eval("id") %>'></asp:Label>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label3" runat="server" Text='<%# Eval("id") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="NAME" SortExpression="NAME">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Eval("name") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("name") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="SALARY" SortExpression="SALARY">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox3" runat="server" Text='<%# Eval("salary") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# Eval("salary") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:CommandField ShowSelectButton="True" />
                <asp:CommandField ShowEditButton="True" />
                <asp:CommandField ShowDeleteButton="True" />
            </Columns>
            <FooterStyle BackColor="#CCCCCC" />
            <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#F1F1F1" />
            <SortedAscendingHeaderStyle BackColor="#808080" />
            <SortedDescendingCellStyle BackColor="#CAC9C9" />
            <SortedDescendingHeaderStyle BackColor="#383838" />
        </asp:GridView>



Now, When you fill the text box for name and salary....and click on the insert button like......


The code to insert the value in grid view..


protected void Insert_Click(object sender, EventArgs e)
    {
        con.Open();
       
        TextBox empNAME = (TextBox)GridView1.FooterRow.FindControl("TextBox4");
        TextBox empSALARY = (TextBox)GridView1.FooterRow.FindControl("TextBox5");
      
       
        String insertquery="insert into emp values('"+empNAME.Text+"','"+empSALARY.Text+"')";
        SqlCommand cmd = new SqlCommand(insertquery, con);
        Response.Write("1 Row has been inserted. ");
        cmd.ExecuteNonQuery();
        con.Close();
        GridView1.EditIndex = -1;
        BindData();

    }




The final image after inserting the values in grid view is....












Monday, 18 April 2011

CLR(Common Language Runtime)

CLR(Common Language Runtime) : The CLR is an application virtual machine.The CLR is described as the "execution engine" of .NET. It's this CLR that manages the execution of programs. The CLR is the engine that compiles the source code in to an intermediate language. This intermediate language is called the Microsoft Intermediate Language(MSIL) also known as CIL(common Intermidiate Language).

Commom Language Runtime

Friday, 15 April 2011

What is .NET Framework

The .NET Framework is a Software Framework that run on the Microsoft Windows.

The .NET Framework includes a large library. It supports several programming languages which allows language interoperability. The .NET library is available to all the programming languages that .NET supports. The Base class library and the CLR(Common Language Runtime) together constitute the .NET Framework.

Base Class Library : The .NET framework's Base Class Library provides user interface, data access,database connectivity, cryptography, web application development, numeric algorithms, and network communications. The class library is used by programmers, who combine it with their own code to produce applications.

.NET Framework
During the execution of the program this MSIL is converted to the native code or the machine code. This conversion is possible through the Just-In-Time compiler. During compilation the end result is a Portable Executable file (PE). 


ADO.NET : ADO.NET is the new database technology of the .NET platform, and it builds on Microsoft ActiveX Data Objects (ADO).

ADO.NET is an integral part of the .NET Compact Framework, providing access to relational data, XML documents, and application data. ADO.NET supports a variety of development needs. You can create database-client applications and middle-tier business objects used by applications, tools, languages or Internet browsers.
ADO.NET

I LOVE MY LIFE.

Hi, This is Nishant Sukhwal.