Home All Groups Group Topic Archive Search About
Author
16 Apr 2005 8:34 PM
Porgányi Géza
Hi!

I have a Datagrid with a Checkbox in a template column. The checkboxes are
checked programatically from database on load. As I uncheck some options and
push a button (postback) then I want to read if a checkbox is checked and
they have the old value, as nothing would happen.

I found articles about this, but they make it with autopostback or
Datagrid.OnSelectedIndexChange method. Which I think is unnecessary.

Is there a solution?

Thanks in advance
Géza

Author
17 Apr 2005 7:01 AM
Riki
Porgányi Géza wrote:
> Hi!
>
> I have a Datagrid with a Checkbox in a template column. The
> checkboxes are checked programatically from database on load. As I
> uncheck some options and push a button (postback) then I want to read
> if a checkbox is checked and they have the old value, as nothing
> would happen.
> I found articles about this, but they make it with autopostback or
> Datagrid.OnSelectedIndexChange method. Which I think is unnecessary.
>
> Is there a solution?

Probably, you are databinding again on postback.
Don't.

Use (VB.NET):
If(Not Page.IsPostback) Then
     ' Databinding goes here
End If

--

Riki
Author
17 Apr 2005 8:38 AM
Porgányi Géza
"Riki" <riki@nospam.com> az alábbiakat írta a következõ hírüzenetben:
eBJB8sxQFHA.***@TK2MSFTNGP12.phx.gbl...
Show quoteHide quote
> Porgányi Géza wrote:
>> Hi!
>>
>> I have a Datagrid with a Checkbox in a template column. The
>> checkboxes are checked programatically from database on load. As I
>> uncheck some options and push a button (postback) then I want to read
>> if a checkbox is checked and they have the old value, as nothing
>> would happen.
>> I found articles about this, but they make it with autopostback or
>> Datagrid.OnSelectedIndexChange method. Which I think is unnecessary.
>>
>> Is there a solution?
>
> Probably, you are databinding again on postback.
> Don't.
>
> Use (VB.NET):
> If(Not Page.IsPostback) Then
>     ' Databinding goes here
> End If
>
> --
>
> Riki
>
Thanks Riki,

But no, I don't databind again.

As a field was false(unchecked) and I check it on the page... It will be
checked on serverside, too. So unchecked->check direction works,
checked->uncheck doesn't.
I guess the problem is, that if I write chkBox.Checked = true, then it
renders "Checked ='checked'" into the HTML.

After postback it is written there again.
Author
3 May 2005 11:30 AM
chan mt
Hi,

i am facing the same problem as you do..

when user selects a Checkbox on the 1st Datagrid page, then if the user
moves to another Datagrid page & comes back to hat 1st page, & deselects
the checkbox item in that 1st page, It just wouldn't go to the Loop
where i have "Checked = False" but instead always go to "Checked = True"

I really don't understand why this happens

please can u let me know if u have found a way of handling the selection
of the Checkboxes?

Regards,
chan

*** Sent via Developersdex http://www.developersdex.com ***
Author
16 May 2005 9:32 AM
Porgányi Géza
Sorry, I found no solution yet
"chan mt" <rschane03-vbfo***@yahoo.com.sg> az alábbiakat írta a következo
hírüzenetben: O2zuDO9TFHA.2***@TK2MSFTNGP15.phx.gbl...
Show quoteHide quote
> Hi,
>
> i am facing the same problem as you do..
>
> when user selects a Checkbox on the 1st Datagrid page, then if the user
> moves to another Datagrid page & comes back to hat 1st page, & deselects
> the checkbox item in that 1st page, It just wouldn't go to the Loop
> where i have "Checked = False" but instead always go to "Checked = True"
>
> I really don't understand why this happens
>
> please can u let me know if u have found a way of handling the selection
> of the Checkboxes?
>
> Regards,
> chan
>
> *** Sent via Developersdex http://www.developersdex.com ***
Author
17 May 2005 1:50 AM
xianxian
same here.. im trying to look up on other forums too..

that's ok, keep me informed again

thanks! =)

*** Sent via Developersdex http://www.developersdex.com ***
Author
31 May 2005 9:40 AM
xianxian
hi,

i found something that is related to what we're looking for.. hope this
may be the solution, im still working on it =)

Check out this link:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vste
chart/html/vbtchTopQuestionsAboutASPNETDataGridServerControl.asp

Look out for "Selecting Multiple Items Using a Check Box (Hotmail
Model)",
then at the section "Editing Multiple Rows At Once", scroll down to find
"Checking for Changed Items"


*** Sent via Developersdex http://www.developersdex.com ***
Author
31 May 2005 2:19 PM
Porgányi_Géza
Hi,

Yes with the CheckedChanged event you can handle this, but then there is a postback, which I try to skip.

  "xianxian" <xianx***@devdex.com> az alábbiakat írta a következo hírüzenetben: %237TZ7ScZFHA.1***@TK2MSFTNGP09.phx.gbl...
  hi,

  i found something that is related to what we're looking for.. hope this
  may be the solution, im still working on it =)

  Check out this link:

  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vste
  chart/html/vbtchTopQuestionsAboutASPNETDataGridServerControl.asp

  Look out for "Selecting Multiple Items Using a Check Box (Hotmail
  Model)",
  then at the section "Editing Multiple Rows At Once", scroll down to find
  "Checking for Changed Items"


  *** Sent via Developersdex http://www.developersdex.com ***
Author
1 Jun 2005 2:31 AM
xianxian
hi,

i don't understand why u say that, datagrid surely will have post back
unless yours is one without paging..

say if user checked a box on the 1st page of the datagrid, then clicks
on next page, that will be a postback already.


under "Checking for Changed Items" it says:

"It is helpful to understand that change events do not, by default, post
the page back to the server. Instead, the event is raised only when the
page is posted some other way (usually via a Click event). "


so definitely u'll have to write coding for the postback event, so that
if the datagrid page is changed, u can handle the items checked before u
load the next page of the grid.

regards,
xianxian

*** Sent via Developersdex http://www.developersdex.com ***
Author
3 Jun 2005 9:25 AM
xianxian
Hi,
i finally had it working :-


Protected Sub RowChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs)
        Dim a As New ArrayList
        If Not Session("SelectResults") Is Nothing Then
            a = CType(Session("SelectResults"), ArrayList)
        End If

        Dim dgItem As DataGridItem = CType(CType(sender,
Control).NamingContainer, DataGridItem)
        Dim rec As Integer = CInt(dgItem.Cells(9).Text)

        If Not a.Contains(rec) Then
            a.Add(rec)
        Else
            Dim chkSel As CheckBox = CType(dgItem.Cells(0).Controls(1),
CheckBox)
            If chkSel.Checked = False Then
                a.Remove(rec)
            End If
        End If

        Session("SelectResults") = a
    End Sub


*PS: "rec" is a record number, just a unique item for every Checkbox in
my Datagrid.
Note that I have to first check whether the item is in my Arraylist,
before i check for Checked=False. If i do it the other way round, it
would not work.


in HTML, just add OnCheckedChanged="RowChanged" :-

<Columns>
                                <asp:TemplateColumn HeaderText="Select">
                                    <ItemTemplate>
                                        <asp:CheckBox id="chkSelect" OnCheckedChanged="RowChanged"
Runat="server"></asp:CheckBox>
                                    </ItemTemplate>
                                </asp:TemplateColumn>
...
</Columns>


That's about all, i suppose
Good Luck =)

*** Sent via Developersdex http://www.developersdex.com ***