Infolink

 

Search This Blog

Jan 31, 2014

ROW_NUMBER() in SQL

Hello guys,

i have make a simple application which contains A Gridview with the thousend of records.
so i am manage it with paging.

IF I WANT TO FILTER GRIDVIEW RECORDS WITH SQL ?

So, i have take two textbox two filtering the gridview as follow.

and i am sending the value in the database as follow.

create table #tmp (id int,name varchar(10))

insert into #tmp values(1,'a')

insert into #tmp values(2,'b')
insert into #tmp values(3,'c')
insert into #tmp values(4,'d') 

select id,name,rownumber,totalrowcnt from
(
    select #tmp.*,ROW_NUMBER() over (order by #tmp.id) rownumber,count(*) over() totalrowcnt
    from #tmp
) result
where result.rownumber between VALUE1 and VALUE2
* here value1 and value2 are textbox value.

So, with this simple SQL query i can filter the gridview records.

Jan 22, 2014

Prevent self closing html tags in .NET

I create an input element, it will self close. How can I prevent this?

<asp:TextBox id="txt1" runat="server"></asp:TextBox
SOLUTION
  1. Tools
  2. Options
  3. Text Editor
  4. HTML
  5. Formatting
  6. Uncheck the box for Auto insert close tag

Jan 21, 2014

Set the tab order in VB.NET

I have a bunch of buttons on a form and when the person presses TAB I want the focus of the controls move in a specific order.

solution :

If you have form with lots of control then manage tab index by below method:
  •     Open form in design mode.
  •     Click on “View” from toolbar --> “Tab Order” at bottom.

Example:




Then just click on controls one by one in order that you want to set tab order.

Jan 12, 2014

C# Event Handlers and Delegates in ASP.Net with Web User Controls

This article should help as a general how to on event handlers and delegates in C# as well as propose a different way to handle cross page methods in your ASP .Net website from a web user control or other page.

Create event handlers and their delegates in the user control, fire them from the methods tied to the internal controls protected events, and define the methods that will handle the new events in the page (see code below).


This article should help as a general how to on event handlers and delegates in C# as well as propose a different way to handle cross page methods in your ASP .Net website from a web user control or other page.

Polymorphisms in C++

When people talk about polymorphism in C++ they usually mean the thing of using a derived class through the base class pointer or reference, which is called subtype polymorphism. But they often forget that there are all kinds of other polymorphisms in C++, such as parametric polymorphism, ad-hoc polymorphism and coercion polymorphism.

These polymorphisms also go by different names in C++,

Subtype polymorphism is also known as runtime polymorphism.
Parametric polymorphism is also known as compile-time polymorphism.

Ad-hoc polymorphism is also known as overloading. 
Coercion is also known as (implicit or explicit) casting.

Creating dynamic textbox

ASPX

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>Untitled Page</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Add Textbox" />

        <asp:Panel ID="Panel1" runat="server" >

       

        </asp:Panel>           

        </div>

    </form>

</body>

</html>


C#


using System;

using System.Web.UI.WebControls;

using System.Collections.Generic;

namespace WebApplication1

{

    public partial class _Default : System.Web.UI.Page

    {

        private List textboxes;
        protected void Page_Load(object sender, EventArgs e)
        {
            PreRender += new EventHandler(_Default_PreRender);
            textboxes = new List();

            if(IsPostBack)
            {
                //recreate Textboxes
                int count = Int32.Parse(ViewState["tbCount"].ToString());

                for (int i = 0; i < count; i++)
                {
                    TextBox tb = new TextBox();
                    tb.ID = "tb" + i;
                    Panel1.Controls.Add(tb);
                    textboxes.Add(tb);
                    tb.Text = Request.Form[tb.ClientID];
                }

            }

        }      

        protected void Button1_Click(object sender, EventArgs e)
        {
            //create new textbox

            TextBox tb = new TextBox();
            tb.ID = "tb" + textboxes.Count;
            Panel1.Controls.Add(tb);
            textboxes.Add(tb);
        }

        void _Default_PreRender(object sender, EventArgs e)
        {
            //remember how many textboxes we had
            ViewState["tbCount"] = textboxes.Count;
        }
    }
}
 

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

private System.Windows.Forms.TextBox[] textboxes;

textboxes = new System.Windows.Forms.TextBox[2];

int cnt=0;

foreach (System.Windows.Forms.TextBox textbox in textboxes)
{
      // the location on the form. you may need to play with this

      // and it should change for each textbox

      textbox.Location = new System.Drawing.Point(88, 50);

      textbox.Name = "textbox"+cnt.ToString();

      textbox.Size = new System.Drawing.Size(173, 20);

      textbox.TabIndex = cnt;

      textbox.Visible = true;

      cnt++;
}


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

public partial class AGEP : IdealFramework.UI.Screen
{

TextBox[] TB1 = new TextBox[18];

public AGEP()
{
InitializeComponent();
}
private void AGEP_Load(object sender, EventArgs e)
{
int sub = 0;
int sub2 = 0;
while (sub < 18)
{
TB1[sub] = new TextBox();
sub2 = sub * 25 + 1;
TB1[0].Location = new Point(5, sub2);
pnlPmtArea.Container.Add(TB1[sub]);
sub++;
}
}

Instantly Increase ASP.NET Scalability


Each time a request for a .NET resource (.aspx, page, .ascx control, etc.) comes in a thread is grabbed from the available worker thread pool in the asp.net worker process (aspnet_wp.exe on IIS 5.x, w3wp.exe on IIS 6/7) and is assigned to a request. That thread is not released back into the thread pool until the final page has been rendered to the client and the request is complete.

Performance Optmization with .NET

I have a web service, so the handler is called multiple times concurrently all the time.

Inside I create SqlConnection and SqlCommand. I have to execute about 7 different commands. Different commands require various parameters, so I just add them once:

command.Parameters.Add(new SqlParameter("@UserID", userID));
command.Parameters.Add(new SqlParameter("@AppID", appID));
command.Parameters.Add(new SqlParameter("@SID", SIDInt));
command.Parameters.Add(new SqlParameter("@Day", timestamp.Date));
command.Parameters.Add(new SqlParameter("@TS", timestamp));

How to connect to an external SQL server database in ASP.NET / VB.NET

Connecting to databases in .NET is different if you are coming from other languages such as PHP. To connect to a database in ASP.NET / .NET in general, you use "Connection Strings" that essentially is the connection information to the database.

First and foremost, in your code behind file within an ASP.NET application (or simply the .vb or .cs file of your .NET desktop application), you will need to first import the namespace that has the relevant database-related classes and methods, etc.

Note: All examples use the Visual Basic language, but the concept is the same for both Visual Basic and C#, for example.

Jan 11, 2014

DateTimePicker ValueChanged and CloseUp Event

some time ago i come to know this problem in my form When the month forward or backward arrow is clicked on my DateTimePicker control it repeatedly fires the ValueChanged event.


I have solve this problem using Closeup event of DatepTimePicker

ValueChanged Event

DateTimePicker ValueChanged Event repeats with month/year arrow

VB.NET


Private Sub datepicker_ValueChanged (sender As Object,e As EventArgs) Handels datepicker.ValueChanged MessageBox.Show("You are in the DateTimePicker.ValueChanged event.")

CloseUp Event


when the user changes the value manually, the CloseUp event obviously isn't triggered

VB.NET
Private Sub datepicker_CloseUp(sender As Object,e As EventArgs) Handels datepicker.CloseUp

MessageBox.Show("You are in the DateTimePicker.CloseUp event.")
Related Posts Plugin for WordPress, Blogger...