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... }
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... > } > >
On Aug 8, 10:26 pm, Sergey Poberezovskiy 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!!!!! :)