Hi ,
I have datagrid with 9 records.I have 3 buttons named as ,view all ,Active,Deactive.
Here my database columns are country,company,logo,status.
If i click view all the records can be viewed pagewise without any error. It is working fine.
The other 2 buttons namely:
Button Active-status is 1
Button DeActive-staus is 0
I have set pagesize= 5 , that is i have 5 records(1,2,3,4,5) in the first page,4 records(6,7,8,9) in second page.
In the first page i have 3 active records (1,3,5), and two deactive records(2,4)
if i click active in the first page only 3 active(1,3,5) should be displayed and if i click deactive only two deactive records (2,4) should be displayed. Instead all the active records(including active records in second page) are also displaying in that page and same problem in deactive also.
Similarly,
In the second page i have two actve records (7,9), and two deactive records(6,8)
if i click active in the second page only 2 active(7,9) should be displayed and if i click deactive only two deactive records (6,8) should be displayed. Instead all the active records(including active records in first page) are also displaying in that page and same problem in deactive also.
My question is i have to display only the active records in the first page.I have set overall pagesize as 5 in my datagrid. How can i set to display only the 3 active records and two deactive records in the first page and same for second page .
I have given the code for Active & Deactive below
ACTIVE BUTTON: (status 1)
Try
strConnString = objCsLgateway.GetConnectionString()
conn = objCsDataBase.GetDbConnection(strConnString)
Dim adap As New SqlDataAdapter("select DISTINCT logo_code,company_name,country_name,category,picture_path from tblLogos where status=1 ", conn)
Dim ds As New DataSet
adap.Fill(ds, "tblLogos")
DataGrid1.CurrentPageIndex = 0
DataGrid1.DataSource = ds
DataGrid1.DataBind()
Catch errEx As Exception
Response.Write(errEx.Message)
End Try
DEACTIVE BUTTON (status 0)
Try
strConnString = objCsLgateway.GetConnectionString()
conn = objCsDataBase.GetDbConnection(strConnString)
Dim adap As New SqlDataAdapter("select DISTINCT logo_code,company_name,country_name,category,picture_path from tblLogos where status=0 ", conn)
Dim ds As New DataSet
adap.Fill(ds, "tblLogos")
DataGrid1.CurrentPageIndex = 0
DataGrid1.DataSource = ds
DataGrid1.DataBind()
Catch errEx As Exception
Response.Write(errEx.Message)
End Try
plz provide me with proper solution and the corrected code.
Regards,
Vijay
Peter ByrnePosted Oct 8, 2006, 11:50 AM
Your initial recordset contains all 9 - {1,2,3,4,5,6,7,8,9}.
Active Records
When you repopulate the datagrid you are binding it to a completely new and different set of records.
For the Active records your recordset contains {1,3,5,7,9}
Deactive Records
When you repopulate the datagrid you are binding it to another completely new and different set set of records.
For the Deactive records your recordset contains {2,4,6,8}
A simple solution to your problem is to display the Active/Deactive records in another DataGrid but you would still have the problem that the complete record set would be displayed.
If you want to pursue your current method of display then you must retain your original full complete dataset - run your Active/Deactivate queries and keep them in a seperate datasets.
You will then have to change what is displayed on a page by page basis based on what is in your active/inactive record sets:
Pseudo Code
To Display the Active Records
foreach (record in currentlyDisplayedRecordsOnPage)
{
if (ActiveRecordSet.Contains(record))
then: Leave As already displayed
Else: Alter the way it is displayed (Make it invisible - or change its colour or whatever )
}
Apply similar logic for Deactive records