ss_blog_claim=4037e1ab37562895784b0e2f995a5eec ss_blog_claim=4037e1ab37562895784b0e2f995a5eec

7.17.2008

Making your Gridview sort in Ascending and Descending Order

Two days ago, our QA tester posted an improvement request for our project on the issue log tracking tool. She wanted a more flexible sorting feature on the gridview.

I initially didn't bother to do it at first coz it was just an improvement and i was still focusing on fixing my bugs. Also, i thought it was easily and can be done in an hour. But when i started doing progress on this issue i realized that it was not as easy as i though i would be.

I'm almost done but i'm encountering a slight problem on one of my classes..

Here's the code:

//Here's the code on my Data Access Layer class:

//********************************

public cls_SqlDataSource(CommandType _CmdType, string _CmdText)
{
this.connectionString = EMS.Configuration.EMSConfiguration.Instance.ConnectionString;
cmd.CommandType = _CmdType;
cmd.CommandText = _CmdText;
}

public SqlDataReader ExecuteReader()
{
SqlConnection Conn = new SqlConnection(this.connectionString);
cmd.Connection = Conn;
SqlDataReader objReader;

try
{
Conn.Open();

objReader = cmd.ExecuteReader();
return objReader;
}
catch (SqlException ex)
{
throw new Exception(ex.Message);
}
finally
{
Conn.Close();
Conn = null;
cmd = null;
objReader = null;
}

}

//********************************************


//And here's the calling class on the Business Layer side of the application

//********************************************

public static ArrayList arListGetEpmMain(int userID, int groupID)
{
SqlDataReader reader = null;

try
{
EMS.DataAccess.cls_SqlDataSource cmd = new cls_SqlDataSource(CommandType.StoredProcedure, "usp_myStoredProcedure");
cmd.AddParameter("@param1", SqlDbType.Int, 8, ParameterDirection.Input, param1);
cmd.AddParameter("@param2", SqlDbType.Int, 8, ParameterDirection.Input, param2);

reader = cmd.ExecuteReader();

if (reader.Read())
{
ArrayList aList = new ArrayList();

while (reader.Read())
{
EPMMain objEPMMain = new EPMMain();

// assign the database values to the object's properties

objEPMMain.IsRead = reader.GetBoolean(23);
objEPMMain.TimeStamp = reader.GetString(1);
objEPMMain.MyID = reader.GetString(0);
objEPMMain.Version = Convert.ToInt32(reader.GetDecimal(33));
objEPMMain.Project = reader.GetString(16);
objEPMMain.SDateTime = Convert.ToDateTime(reader.GetString(17));
objEPMMain.DateDue = Convert.ToDateTime(reader.GetString(28));
objEPMMain.CatName = reader.GetString(19);
objEPMMain.CusName = reader.GetString(20);
objEPMMain.UName = reader.GetString(21);
objEPMMain.IndName = reader.GetString(22);
objEPMMain.IsAlrt = Convert.ToInt32(reader.GetBoolean(12));
aList.Add(objEPMMain);
}

return aList;
}

return null;

}

catch (Exception ex)
{
throw ex;
}

finally
{
reader.Close();
}
}

//****************************************************



I'm using .Net Framework 2.0 and Windows XP OS. Any help will greatly be appreciated!

**THIS ISSUE IS ALSO POSTED ON THE MICROSOFT FORUMS.

No comments:

Post a Comment