473,769 Members | 3,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.W ebControls.Imag e img1 =
(System.Web.UI. WebControls.Ima ge)e.Item.Cells[7].Controls[1];
int iIndx = e.Item.DataSetI ndex;
/*
0 Disabled
1 Approved
2 Waiting For Approval
3 Rejected
4 Locked
*/
int iResultSR = dsListBuilders. Tables["bb_saved_build ers"].Rows[iIndx]
["sales_rep_appr oved"].ToString() == string.Empty?
2:int.Parse(dsL istBuilders.Tab les["bb_saved_build ers"].Rows[iIndx]
["sales_rep_appr oved"].ToString());

switch(iResultS R)
{
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.g if";
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 2795
Scott,

Instead of locating the data in the original table
dsListBuilders. Tables["bb_saved_build ers"].Rows[iIndx]
use the grid source data:
DataRow row = (e.Item.ItemDat a is DataRow) ? e.Item.ItemData as DataRow :
(e.Item.ItemDat a as DataRowView).Ro w;
int iResultSR = (row["sales_rep_appr oved"].ToString() ==
string.Empty)?2 :int.Parse(row["sales_rep_appr oved"].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.W ebControls.Imag e img1 =
(System.Web.UI. WebControls.Ima ge)e.Item.Cells[7].Controls[1];
int iIndx = e.Item.DataSetI ndex;
/*
0 Disabled
1 Approved
2 Waiting For Approval
3 Rejected
4 Locked
*/
int iResultSR = dsListBuilders. Tables["bb_saved_build ers"].Rows[iIndx]
["sales_rep_appr oved"].ToString() == string.Empty?
2:int.Parse(dsL istBuilders.Tab les["bb_saved_build ers"].Rows[iIndx]
["sales_rep_appr oved"].ToString());

switch(iResultS R)
{
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.g if";
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
<SergeyPoberezo vs...@discussio ns.microsoft.co mwrote:
Scott,

Instead of locating the data in the original table
dsListBuilders. Tables["bb_saved_build ers"].Rows[iIndx]
use the grid source data:
DataRow row = (e.Item.ItemDat a is DataRow) ? e.Item.ItemData as DataRow :
(e.Item.ItemDat a as DataRowView).Ro w;
int iResultSR = (row["sales_rep_appr oved"].ToString() ==
string.Empty)?2 :int.Parse(row["sales_rep_appr oved"].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.W ebControls.Imag e img1 =
(System.Web.UI. WebControls.Ima ge)e.Item.Cells[7].Controls[1];
int iIndx = e.Item.DataSetI ndex;
/*
0 Disabled
1 Approved
2 Waiting For Approval
3 Rejected
4 Locked
*/
int iResultSR = dsListBuilders. Tables["bb_saved_build ers"].Rows[iIndx]
["sales_rep_appr oved"].ToString() == string.Empty?
2:int.Parse(dsL istBuilders.Tab les["bb_saved_build ers"].Rows[iIndx]
["sales_rep_appr oved"].ToString());
switch(iResultS R)
{
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.g if";
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
2391
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 field... This grid displayes results based on users search.. public static int numberDiv; private void Page_Load(object sender, System.EventArgs e) {
8
1957
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 button that inserts a new row in the SQL table and then refresh the datagrid.
2
1574
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 do: If IsPostBack Then
2
1610
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. The following control simply responds to a sort request and/or a pageing reqeust with an empty table (header only). Any ideas ? Code behind : namespace OakTree.data {
1
1165
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 accomplish is this: I have a datagrid that has several columns directly bound from data table and on each row of the grid, the user has the ability to select that person displayed. When the user does NOT sort this grid their selections are...
11
2148
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 populate the data if !postback.
2
2468
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 checkbox control. where i'm at: i can retrieve a count of the selected checkboxes, but don't know how to get the related id's (in the 1st column).
1
4237
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 the example to work. I created the following two classes, provided with the example: *-*-**-*-*-*-*-*-*-*-*-*-**-*-*-*-*-CheckBoxColumn Class:-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-**-*-*-*
0
2090
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 help........pls urgent ========================================================= <%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm3.aspx.vb" Inherits="TestDatagrids.WebForm3"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">...
0
10206
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10035
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8863
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3556
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.