Tuesday, September 23, 2008

Issues with Response.End()

I found some issues in Response.End() while working upon Reports.  

Wednesday, September 17, 2008

Static Methods in C#

If you have to access a method in a class from outer side, you could have two ways.  First one is create an object for the class which contains that method and using that object call the method.

public class A
{
public void GoodMorning()
{
// code;
}
}

public class B()
{
A objA = new A();
objA.GoodMorning();
}


  Second method is you can create the method using 'static' so that you dont need to create an object for the class. You can directly call the function like this:

public class B()
{
A.GoodMorning();
}

Restrictions on methods having static are:

a)  If you wish to use a variable in side the static method, which is declared outside the static method ie, within class; you must declare that variable as static. Otherwise it will not intake that variable inside the static method.

Monday, September 8, 2008

Add onclick event in Gridview's page index

In gridview, you have a field in which checkboxes are available and using that checkeditems you are going to do some process, say update.  Doing so, when user checked the checkbox(es) and tried to click on next page, the selected items will be vanished.  If you wish to give a warning message as "if you choose next page to navigate, then selected items will lost".  What could you do ?

We cannot directly get the page index value.  Doing so, in Row_DataBound event, check as
e.Row.RowType as pager.  If so, take the count of pages as below :

int count = e.Rows.cells[0].controls[0].controls[0].count;

for(int index=0; index<=count-1;index++)
 { System.Web.UI.WebControls.TableCell cell = (System.Web.UI.WebControls.TableCell)e.Rows.cells[0].controls[0].controls[0]; cell.Attributes.Add("onclick","alert('If you choose next page to navigate, the selected items will lost.')"; } 

Pager row will be rendered as,


"
123
"
.To access this, we have to use controls[0].  

Sunday, September 7, 2008

Dynamic gridview with add item option in footer

While you binding a gridview dynamically, its must that atlease one record should be needed so that footer will get displayed.  While there is no records from database, footer will not be displayed.  To overcome this, you have to create a fake record while get and bind records and have to hide that record in row created using a hidden variable.

How to set Login and Password for SQL Server Authentication mode?

While you configure MS SQL, it will get configured under windows authentication.  You have to change this mode and set password.  
Login using windows authetication and open a query browser.  Type the following:

ALTER LOGIN sa ENABLE
GO
ALTER LOGIN sa WITH PASSWORD='password'
GO

First of all you enabling SQL Authentication mode and then set password for sa.  sa is the default login.