RE: Row Selector Column
- From: stcheng@xxxxxxxxxxxxxxxxxxxx (Steven Cheng[MSFT])
- Date: Thu, 17 Nov 2005 03:32:16 GMT
Hi Terry,
Welcome.
Seems you're still on your way developing the custom DataGrid Columns :-).
As for the CheckBox postback events problem you mentioned in this post, I
think you assumption about the intializing setting on the Header
CheckBox.Checked property(as false) is reasonable, and I've also
encountered such problems when developing composite control with postback
and status changes.. (Such control like CheckBox, TextBox's XXXchanged
event is based on the comparation between the control instance's property
value and the value retrieved from viewstate....) So have you tried
removing the ctl.Checked = False line in the following code to see
whether it helps?
=============
Select Case itemType
Case ListItemType.Header
Dim ctl As CheckBox = New CheckBox
ctl.AutoPostBack = True
ctl.Checked = False
cell.Controls.Add(ctl)
============
Also, as for "checking All", "Unchecking All" functionality, we can also
consider use clientside script to make them all complete at clientside
without postback...
Thanks,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Terry Holland" <terryeholland@xxxxxxxxxxxxxxxx>
| Subject: Row Selector Column
| Date: Wed, 16 Nov 2005 11:25:46 -0000
| Lines: 113
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1506
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
| Message-ID: <OaeWICq6FHA.2012@xxxxxxxxxxxxxxxxxxxx>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| NNTP-Posting-Host: host221.multiserv.com 194.200.135.221
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridcontrol:14721
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
|
| I have created a custom control that dynamically creates a datagrid at
| runtime. The datagrid is made up of a collection of custom columns. One
of
| my custom columns is a Row Selecter column. This comprises a Checkbox for
| each row and one in the header of datagrid.
|
| My row selection is working fine and I am able to loop through the
selected
| items in my grid and perform an action on them. What I want to be able to
| do now is give the user the ability to select or un-select all rows by
| clicking the checkbox in the header.
|
| The trouble that I am experiencing is that the CheckChanged event of the
| checkbox in the header only fires if the value changes from the value that
| it is when it is dynamically created.
|
| Each postback causes my custom control to be built. When it is built the
| row selector column (clsDGCCheckBoxColumn) is added and the InitializeCell
| method adds a checkbox to the header column with the checked value =
False.
| When the user checks this control, the SelectColumn method runs
correctly.
| If the user unchecks the checkbox in the header, the SelectColumn method
| does not run. Im assuming that this is because the value of this control
| when it is built is False and when the user unchecks the control it is
once
| again False, therefore the value has not changed therefore the event does
| not fire.
|
| Could someone advise me how to get around this problem - I guess that I
need
| to modify InitializeCell so that the value that I set the checkbox to is
as
| it was before postback.
|
| Thanks
|
| Terry Holland
|
| ##############################
| Custom CheckBox Column
| ##############################
| Imports System.Web.UI.WebControls
| Imports System.Web.UI
| Imports System.ComponentModel
|
| Public Class clsDGCCheckBoxColumn
| Inherits clsCustomDGC_BASE
|
| Public Sub New(ByVal objDGC As clsDataGridColumn)
| MyBase.New(objDGC, "chk")
| m_clrBackColor = System.Drawing.Color.LightCyan
| End Sub
|
| Public Overrides Sub InitializeCell(ByVal cell As TableCell, ByVal
| columnIndex As Integer, ByVal itemType As ListItemType)
| MyBase.InitializeCell(cell, columnIndex, itemType)
|
| Select Case itemType
| Case ListItemType.Header
| Dim ctl As CheckBox = New CheckBox
| ctl.AutoPostBack = True
| ctl.Checked = False
| cell.Controls.Add(ctl)
|
| AddHandler ctl.CheckedChanged, AddressOf SelectColumn
'(Me,
| ctl.Checked)
|
| Case ListItemType.Item, ListItemType.AlternatingItem,
| ListItemType.EditItem, ListItemType.SelectedItem
|
| Dim ctl As CheckBox = New CheckBox
| SetControlProperties(cell, ctl)
|
| cell.Controls.Add(ctl)
|
| AddHandler cell.DataBinding, AddressOf Cell_DataBinding
| Case Else
|
| End Select
| End Sub
|
| Private Sub Cell_DataBinding(ByVal sender As Object, ByVal e As
| EventArgs)
| Dim cell As TableCell = sender
| Dim item As DataGridItem = cell.NamingContainer
| Dim ctl As CheckBox = item.FindControl(m_strID)
| Dim pd As PropertyDescriptor =
| TypeDescriptor.GetProperties(item.DataItem).Find(m_strDataField, True)
|
| Try
| Dim obj1 As Object = pd.GetValue(item.DataItem)
|
| ctl.Checked = CType(obj1, Boolean)
| Catch ex As Exception
| Throw New Exception("Invalid dataField for custom column
| clsDGCLabel")
| End Try
| End Sub
|
|
|
| Private Sub SelectColumn(ByVal sender As Object, ByVal e As
EventArgs) '
| ByVal booSelect As Boolean)
| Dim ctlHeader As CheckBox = sender
| Dim grid As DataGrid = ctlHeader.NamingContainer.NamingContainer
| Dim booSelect As Boolean = ctlHeader.Checked
|
| Dim o As CheckBox
|
| For Each dgi As DataGridItem In grid.Items
| o = dgi.FindControl(m_strID)
| o.Checked = booSelect
| Next
| End Sub
| End Class
|
|
|
|
|
.
- Follow-Ups:
- Re: Row Selector Column
- From: Terry Holland
- Re: Row Selector Column
- References:
- Row Selector Column
- From: Terry Holland
- Row Selector Column
- Prev by Date: Re: Datagrid Formatting
- Next by Date: Re: Row Selector Column
- Previous by thread: Row Selector Column
- Next by thread: Re: Row Selector Column
- Index(es):
Relevant Pages
|