473,327 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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

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...
}

Aug 8 '07 #1
2 2770
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" wrote:
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...
}

Aug 9 '07 #2
On Aug 8, 10:26 pm, Sergey Poberezovskiy
<SergeyPoberezovs...@discussions.microsoft.comwrot e:
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" wrote:
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!!!!! :)

Aug 9 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: pmud | last post by:
Hi, I am using teh following code for sorting the data grid but it doesnt work. I have set the auto generate columns to false. & set the sort expression for each field as the anme of that...
8
by: Inigo Jimenez | last post by:
I have an ASP .net web application installed in a Windows 2003 server. This web application has a webform that has a Datagrid. This Datagrid is filled with the data of a SQL table. I have a...
2
by: Bob Trabucco | last post by:
Hello all, I have a Datagrid on a page. 1 column is a template column with a checkbox (unbound). The rest of the columns are databound that are added programatically. If in the Page_Load I...
2
by: ddaniel | last post by:
I have read many posts and seen many papers on the different techniques for sort and filtering datagrids. Many do re-queries against the dB ala Fritz Onion. I am trying to leverage the Dataview....
1
by: David McCormick | last post by:
I have been scouring the message boards before I posted this question hoping to find an answer regarding datagrids and their behaviour after a sort command has been invoked. What I am trying to...
11
by: rkbnair | last post by:
I have created a datagrid in my aspx with the 'AllowSorting' property to true. When clicking on the column header, the page refreshes. However the sorting is not done. Am I missing anything? I...
2
by: Mortar | last post by:
i have a datagrid with 2 columns. the 1st column contains an id which will be used by the database for the selected checkbox records. the 2nd column is a template column containing a server...
1
by: sianan | last post by:
I tried to use the following example, to add a checkbox column to a DataGrid in an ASP.NET application: http://www.codeproject.com/aspnet/datagridcheckbox.asp For some reason, I simply CAN'T get...
0
by: rupalirane07 | last post by:
Both grids displays fine. But the problem is only parent datagrid sorting works fine but when i clik on child datagrid for sorting it gives me error: NullReferenceException error Any...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.