Friday, December 27, 2013

ASP.NET : Call a function inside Gridview

In .aspx page.....

<asp:GridView ID="GV" runat="server"  AutoGenerateColumns="False"
onrowcommand="GV_RowCommand" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px"  CellPadding="3" ForeColor="Black" GridLines="Vertical">


<Columns>

                    <asp:TemplateField HeaderText="S.No.">

                    <ItemTemplate>

                             
                                <%#(Container.DataItemIndex + 1)%>.

                    </ItemTemplate>

                    </asp:TemplateField>

                    <asp:BoundField HeaderText="Admission No." DataField="RollNo" />

                    <asp:TemplateField HeaderText="Student Name">

                    <ItemTemplate>

                    <asp:LinkButton ID="LStudentName" runat="server"  

                          CommandName="LStudentName" 
                         CommandArgument='<%#Eval("RollNo") %>' 
                         Text='<%#Eval("StudentName") %>'></asp:LinkButton>

                    </ItemTemplate>

                    </asp:TemplateField>

<asp:TemplateField HeaderText="Status">

                    <ItemTemplate>

                    <asp:Label ID="lblstatus" runat="server"

Text='<%#GenrateStatus(Eval("Status"))%>' ></asp:Label>

                    </ItemTemplate>

  </asp:TemplateField>

</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" />

                <AlternatingRowStyle BackColor="#CCCCCC" />

            </asp:GridView>


In .cs page....

 public static string GenrateStatus(object status)

    {

        string strStatus = status.ToString();

        if (strStatus == "0")

            strStatus= "Pending";

        else if (strStatus == "1")

            strStatus= "Updated";

        return strStatus;

    }

Wednesday, October 16, 2013

AutoNumber Column In GridView DataList ASP.NET 4.0, 3.5, 2.0


We can add AutoNumber column by using Container.DataItemIndex property in html markup of the Gridview.

<title>Auto Number Cloumn in GridView </title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" 
              AllowPaging="True" AutoGenerateColumns="False"
              DataSourceID="SqlDataSource1" PageSize="6" 
              AlternatingRowStyle-BackColor="#006699" 
              AlternatingRowStyle-ForeColor="#FFFFFF" >
    <Columns>
    <asp:TemplateField HeaderText="Serial Number">
    <ItemTemplate>
        <%# Container.DataItemIndex + 1 %>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="Name" HeaderText="Name" 
                    SortExpression="Name" />
    <asp:BoundField DataField="Location" HeaderText="Location" 
                    SortExpression="Location" />
    </Columns>
    </asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [Name], [Location] FROM [Details]">
</asp:SqlDataSource>

Saturday, August 31, 2013

New Features in ASP.NET 4.5

There are too many features in ASP.NET 4.5 to cover in one post, so I'll stick with some of the notable features added or enhanced in this version.
  • Web Sockets: Full support for the Web Sockets HTML5 standard is available with ASP.NET 4.5 running on IIS 8.0 via the SignalR library. This allows you to easily add real-time Web functionality to applications.
  • Authentication: There is now a universal provider (DefaultMembershipProvider) for simplification. In addition, the OAuth protocol is embraced.
  • Async programming: While this feature is not ASP.NET-specific, it is worth noting that C# 5 and Visual Basic 11 provide async support without using multiple threads (via async and await keywords).
  • Web publishing: This feature has been enhanced, whereas you can compare local and remotes files, publish only selected files, and so forth.
  • Web API: This API provides the REST approach to building applications -- a key difference from the WCF alternative. In addition, the Web API now includes extensive OData support, which is another instance of Microsoft embracing open source standards.
  • Friendly URLs: The popularity of tinyurl demonstrates the widespread problem of keeping up with long, arcane URLs. This feature is now available with ASP.NET applications via the FriendlyURLs feature.
  • Mobile: The explosion of smartphones, eReaders and other mobile devices has changed the landscape for Web application development. HTML5 support is supposed to simplify mobile application development. In addition, MVC 4 includes mobile templates, and there are a variety of mobile device emulators that can be used in Visual Studio 2012.
  • IIS: This allows you to use new features available in Internet Information Server (IIS) 8.0. Some of these features include prefetching and application initialization like application ping on startup. Also, an express edition of IIS is now available.