Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Problem sorting a Datagrid with Checkbox columns (checkboxes not following sort)

Reply
Thread Tools

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

 
 
Scott
Guest
Posts: n/a
 
      08-08-2007
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...
}

 
Reply With Quote
 
 
 
 
=?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?=
Guest
Posts: n/a
 
      08-09-2007
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...
> }
>
>

 
Reply With Quote
 
 
 
 
Scott
Guest
Posts: n/a
 
      08-09-2007
On Aug 8, 10:26 pm, Sergey Poberezovskiy
<(E-Mail Removed)> wrote:
> 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!!!!!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
database columns vs. gui columns and sorting ittay.dror@gmail.com Java 5 03-04-2006 10:48 AM
Dynamic columns not sorting in DataGrid =?Utf-8?B?amF2YXRvcGlh?= ASP .Net 0 10-01-2004 11:37 PM
Binded Datagrid Formatting columns or hiding columns ton ASP .Net Web Controls 2 02-11-2004 04:09 AM
Problem sorting datagrid when creating columns programatically Dima ASP .Net Web Controls 0 01-07-2004 07:17 PM
Columns and Inherited Datagrid...Active Schema does not support columns rob thomson ASP .Net Datagrid Control 0 09-04-2003 03:09 PM



Advertisments