Wrox Programmer Forums
|
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 18th, 2004, 04:55 PM
Authorized User
 
Join Date: Jun 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default State of CheckBox in ItemTemplate of DataGrid

Hi,
I have two seperate datagrids on the same page with checkbox as an Itemtemplate Column in each one. Both database get filled up with data from database. CheckBoxes are checked(marked)by user after rows are displayed.

After selecting rows, when user clicks a button for processing these rows a button event is raised. In this event CheckBox state is checked to find which rows are selected. Here CheckBox state remains always unchecked, eventhough some of the checkboxes are checked by user. I am using javscript to put checkmark in checkboxes. And I have marked Autopostback=false for checkbox;
Here is the code snippet:

1)javascript:
=============

<script>
        <script>function check(chkB)
        {
            var xState=chkB.checked;

            if(xState)
            {
                chkB.Checked = true;
            }
            else
            {
                chkB.Checked = false;
            }
        }
        </script>

2)Html of ItemTemplate
====================
                            <asp:TemplateColumn>
                                    <HeaderTemplate>
                                        <asp:Label id="lblchkAll" runat="server" ToolTip="Select each row">SelectTo</asp:Label>
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <asp:CheckBox id="chkSelect" onclick="javascript:check(this);" runat="server" Text="Remove" ToolTip="Select/Deselect each row" AutoPostBack="False"></asp:CheckBox>
                                    </ItemTemplate>

3)CodeBehind of Button Click Event
=================================
        private void btnTrimPrv_Click(object sender, System.EventArgs e)
        {
            CheckBox chkBox = new CheckBox();
            DataSet ds = (DataSet)Cache.Get("dsPrv");
            foreach(DataGridItem dgi in this.QueryGridPrv.Items)
            {
                chkBox = (CheckBox)dgi.Cells[0].Controls[1];
                if(chkBox != null && chkBox.Checked)
                {
                    string strItemIndex = this.QueryGridPrv.DataKeys[dgi.ItemIndex].ToString();
                    ListItem li = new ListItem("ID=" + strItemIndex, strItemIndex);
                    if(ds.Tables.Contains(li.Value))
                    {
                        ds.Tables.Remove(li.Value);
                    }
                }
            }

            ds.AcceptChanges();
            this.QueryGridPrv.DataSource = ds;
            this.QueryGridPrv.DataBind();

        }

In above code

 if(chkBox != null && chkBox.Checked)
always remains "false". Why true state of checkbox is not refleted in post back? Your suggestions will be truely appriciated.
Thank you.

Bharat Gadhia


Bharat Gadhia
__________________
Bharat Gadhia
 
Old August 19th, 2004, 01:26 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Set this attribute of that control as true. That should help.

EnableViewState="true"

Cheers!

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView Checkbox ItemTemplate angelicagm ASP.NET 2.0 Professional 3 May 31st, 2007 04:44 AM
Checkbox state cq_ted ASP.NET 1.x and 2.0 Application Design 0 May 9th, 2006 12:56 AM
error setting ItemTemplate asp:DataGrid jackiew General .NET 3 April 10th, 2006 02:59 PM
inherited web datagrid and ItemTemplate error ochanarachel General .NET 0 December 25th, 2004 04:52 PM
Error while trying to determine state of checkbox savoym C# 2 February 19th, 2004 09:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.