Problem sorting a Datagrid with Checkbox columns (checkboxes not following sort)

S

Scott

I am trying to sort a datagrid which contains 5 checkbox columns. All
other columns sort properly except these 5 checkbox columns which dont
sort at all.

I am using ASP.NET 1.1 and this code is located in a user control.

The code snippet for binding the checkbox control is as follows and is
found in the ItemDataBound event for the datagrid. It appears that
the index value never changes...it always seems to reference the
orginal dataset index.

Any help would be greatly appreciated.

try
{
System.Web.UI.WebControls.Image img1 =
(System.Web.UI.WebControls.Image)e.Item.Cells[7].Controls[1];
int iIndx = e.Item.DataSetIndex;
/*
0 Disabled
1 Approved
2 Waiting For Approval
3 Rejected
4 Locked
*/
int iResultSR = dsListBuilders.Tables["bb_saved_builders"].Rows[iIndx]
["sales_rep_approved"].ToString() == string.Empty?
2:int.Parse(dsListBuilders.Tables["bb_saved_builders"].Rows[iIndx]
["sales_rep_approved"].ToString());

switch(iResultSR)
{
case 0:
img1.ImageUrl="../../images/greybox.gif";
break;
case 1:
img1.ImageUrl="../../images/checkboxyes.gif";
break;
case 2:
img1.ImageUrl="../../images/checkboxno.gif";
break;
case 3:
img1.ImageUrl="../../images/redcheckboxno.gif";
break;
case 4:
img1.ImageUrl="../../images/lock.gif";
break;
default:
img1.ImageUrl="../../images/checkboxno.gif";
break;
}
}
catch(Exception exBinding1)
{
//ignore...
}
 
G

Guest

Scott,

Instead of locating the data in the original table
dsListBuilders.Tables["bb_saved_builders"].Rows[iIndx]
use the grid source data:
DataRow row = (e.Item.ItemData is DataRow) ? e.Item.ItemData as DataRow :
(e.Item.ItemData as DataRowView).Row;
int iResultSR = (row["sales_rep_approved"].ToString() ==
string.Empty)?2:int.Parse(row["sales_rep_approved"].ToString());
 
S

Scott

Scott,

Instead of locating the data in the original table
dsListBuilders.Tables["bb_saved_builders"].Rows[iIndx]
use the grid source data:
DataRow row = (e.Item.ItemData is DataRow) ? e.Item.ItemData as DataRow :
(e.Item.ItemData as DataRowView).Row;
int iResultSR = (row["sales_rep_approved"].ToString() ==
string.Empty)?2:int.Parse(row["sales_rep_approved"].ToString());



Scott said:
I am trying to sort a datagrid which contains 5 checkbox columns. All
other columns sort properly except these 5 checkbox columns which dont
sort at all.
I am using ASP.NET 1.1 and this code is located in a user control.
The code snippet for binding the checkbox control is as follows and is
found in the ItemDataBound event for the datagrid. It appears that
the index value never changes...it always seems to reference the
orginal dataset index.
Any help would be greatly appreciated.
try
{
System.Web.UI.WebControls.Image img1 =
(System.Web.UI.WebControls.Image)e.Item.Cells[7].Controls[1];
int iIndx = e.Item.DataSetIndex;
/*
0 Disabled
1 Approved
2 Waiting For Approval
3 Rejected
4 Locked
*/
int iResultSR = dsListBuilders.Tables["bb_saved_builders"].Rows[iIndx]
["sales_rep_approved"].ToString() == string.Empty?
2:int.Parse(dsListBuilders.Tables["bb_saved_builders"].Rows[iIndx]
["sales_rep_approved"].ToString());
switch(iResultSR)
{
case 0:
img1.ImageUrl="../../images/greybox.gif";
break;
case 1:
img1.ImageUrl="../../images/checkboxyes.gif";
break;
case 2:
img1.ImageUrl="../../images/checkboxno.gif";
break;
case 3:
img1.ImageUrl="../../images/redcheckboxno.gif";
break;
case 4:
img1.ImageUrl="../../images/lock.gif";
break;
default:
img1.ImageUrl="../../images/checkboxno.gif";
break;
}
}
catch(Exception exBinding1)
{
//ignore...
}- Hide quoted text -

- Show quoted text -

Thanks Sergey, after I realized that the line should read
e.Item.DataItem...everything works great!!!

Thanks alot...You have been a great help!!!!! :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top