[CLOSED] V(0.8) How to Read Checkbox Group using C# Code Like Asp CheckGroup Control

  1. #1

    [CLOSED] V(0.8) How to Read Checkbox Group using C# Code Like Asp CheckGroup Control

    Hi,

    We using Checkbox group for creating dynamically when page Loads. There is No problem when loading dynamically the Check box group. But When reading the Checkbox Group from Form for Saving into Database it throwing Error. We need to store the Checkbox group values into the String with Split Character. Below is the Code what we are trying to Read:



    ASPX PAGE:
    <ext:FieldSet ID="FsetProcessRoute" runat="server" Collapsible="true">
    <Body>
    <ext:CheckboxGroup ID="ChkProcessRoute" runat="server" ColumnsNumber="5" Vertical="true"
    Width="650" EnableViewState="true" LabelSeparator="">
    </ext:CheckboxGroup>
    </Body>.....
    DYNAMIC CREATION ON PAGE LOAD
    ...
    DataSet dsGridFunction = new DataSet();
    dsGridFunction = objBLLProcess.ProcessInquiryGridBind(objGridBind);
     
    for (int i = 0; i < dsGridFunction.Tables[0].Rows.Count; i++)
    {
    Checkbox chk = new Checkbox();
    chk.ID = dsGridFunction.Tables[0].Rows[i]["ProcessCode"].ToString();
    chk.BoxLabel = dsGridFunction.Tables[0].Rows[i]["ProcessName"].ToString();
    chk.EnableViewState = false;
    ChkProcessRoute.Items.Add(chk);
     
    }
     
    DataSet dsChkProcess = objBLLInquiry.getSelectData(objGridBind);
    for (int Counter = 0; Counter < dsChkProcess.Tables[0].Rows.Count; Counter++)
    {
    if (dsChkProcess.Tables[0].Rows[Counter]["Checked"].ToString() == "1")
    {
    ChkProcessRoute.Items[Counter].Checked = true;
    }
    else
    {
    ChkProcessRoute.Items[Counter].Checked = false;
    }
    }
    ........
    ERROR WHEN EXECUTING THE FOLLOWING CODE:
    ...
    string Lstr = string.Empty;
     
    for (int i = 0; i < ChkProcessRoute.Items.Count; i++)
    {
    if (ChkProcessRoute.Items[i].Checked == true)
    {
    Lstr += ChkProcessRoute.Items[i].Value + ",";
    }
    }
    ....
    Last edited by Daniil; Sep 03, 2010 at 6:27 PM. Reason: [CLOSED]
  2. #2
    Hello!

    Could you clarify where the code that producing an error is placed? I supposed it's in a handler of AjaxEvent, right?
    Is there a condition like
    if (!Ext.IsAjaxRequest)
    { 
    //Creating CheckboxGroup's items
    }
    in the Page_Load?

    If so, it needs to remove this if you want to handle the CheckboxGroup's items on server side. In other words these items must be recreated during each ajax request. There is the same situation with the isPostBack condition.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < 5; i++)
            {
                Checkbox chk = new Checkbox();
                chk.ID = "Checkbox" + i;
                chk.BoxLabel = "BoxLabel" + i;
                chk.EnableViewState = false;
                chk.Checked = (i % 2 == 0) ? true : false;
                CheckboxGroup1.Items.Add(chk);
            }
    
        }
    
        protected void Button_Click(object sender, AjaxEventArgs e)
        {
            string Lstr = string.Empty;
            for (int i = 0; i < CheckboxGroup1.Items.Count; i++)
            {
                if (CheckboxGroup1.Items[i].Checked == true)
                {
                    Lstr += CheckboxGroup1.Items[i].Value + ",";
                }
            }
            Ext.Msg.Alert("", Lstr).Show();
        }
    </script>
    
    <!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Coolite Toolkit Example</title>
    </head>
    <body>
        <form runat="server">
        <ext:ScriptManager runat="server" />
        <ext:CheckboxGroup ID="CheckboxGroup1" runat="server" />
        <ext:Button runat="server" Text="Click me">
            <AjaxEvents>
                <Click OnEvent="Button_Click" />
            </AjaxEvents>
        </ext:Button>
        </form>
    </body>
    </html>
  3. #3

    This Scenario is not Working for Us In CheckBoxGroup

    Hi,

    In Our Case, on Page Load Check Box Group's Contents should load from Table Value. It has to Shown in the Form. If once User Checks the Checkboxes in the Check Group and Click the Save button, then it has to read the Respective Checked Checkboxes from CheckBoxgroup as True and Load it into the string. Let Me Give you the Steps what we are trying to Implement.

    Step 1: Check Boxes Loaded From TABLE1 into Check Group - In This Dynamic Load No Problem.

                DataSet dsGridFunction = new DataSet();
                dsGridFunction = objBLLProcess.ProcessInquiryGridBind(objGridBind);
    
                for (int i = 0; i < dsGridFunction.Tables[0].Rows.Count; i++)
                {
                    Checkbox chk = new Checkbox();
                    chk.ID = dsGridFunction.Tables[0].Rows[i]["ProcessCode"].ToString();
                    chk.BoxLabel = dsGridFunction.Tables[0].Rows[i]["ProcessName"].ToString();
                    chk.EnableViewState = false;
                    ChkProcessRoute.Items.Add(chk);
    
                }

    Step 2: User Has to Check the Check Boxes and Click the Save Button

    Step 3: Now In Save Click Event Checked Checkboxes has to Read into String And has to Save into TABLE2

        string Lstr = string.Empty;
              for (int i = 0; i < ChkProcessRoute.Items.Count; i++) // In This Line : ChkProcessRoute.Items.Count is always 0 so It is not Looping
                {
                   if (ChkProcessRoute.Items[i].Checked == true                {
                        Lstr += ChkProcessRoute.Items[i].Value + ",";
                    }
                }
    
    
    or
    //If suppose we Used The following Code for Reading The Check box  the Error Thrown
         string Lstr = string.Empty;
         DataSet dsChkProcess = objBLLProcess.ProcessInquiryGridBind(objGridBind);
             for (int Counter = 0; Counter < dsChkProcess.Tables[0].Rows.Count; Counter++)
            {
             if (ChkProcessRoute.Items[Counter].Checked == true))//In This Line Error:ArgumentOutofRange Exception was Caught
           {
            Lstr += ChkProcessRoute.Items[Counter].Value + ",";
          }
  4. #4
    Hi P2E,

    Please post a full .aspx code sample demonstrating how you have things configured. Including all page events.

    I think the issue is you're not recreating the components during subsequent (DirectEvent) requests.

    You mention using the standard <asp:CheckBox> controls. Can you post a sample demonstrating this scenario using just <asp:> controls?
    Geoffrey McGill
    Founder
  5. #5

    How Can i read Client Side Changes?

    Hi,

    How can i read the client Side Changes on the Server side when i am using CheckBoxGroup. If i recreate the Checkbox Items during postback the client side changes would be lossed since we disable the Viewstate for the Checkbox group control and also i checked CheckboxGroup does not retain the state during Postback even if the Viewstate is Enabled. Please Advice


    <%@ Page Language="C#" %>
      
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
      
    <script runat="server"> 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!IsPostBack)
                {
                    ...
                    ProcessRouteBind();
                    ... 
                 }
            
        }
    
        private void ProcessRouteBind()
        {
           try
            {
                object[] objGridBind = new object[5];
                objGridBind[0] = UserSession.CompanyCode;
                objGridBind[1] = UserSession.BranchCode;
                objGridBind[2] = FabricInwardNo;
                objGridBind[3] = FabricQualityCode;
                objGridBind[4] = Dia;
    
                BLLFabricInwardDetails objBLLFabricInwardDetails = new BLLFabricInwardDetails();
                BLLProcess objBLLProcess = new BLLProcess();
                DataSet dsGridFunction = new DataSet();
                dsGridFunction = objBLLProcess.ProcessInquiryGridBind(objGridBind);
    
                for (int i = 0; i < dsGridFunction.Tables[0].Rows.Count; i++)
                {
                    Checkbox chk = new Checkbox();
                    chk.ID = dsGridFunction.Tables[0].Rows[i]["ProcessCode"].ToString();
                    chk.BoxLabel = dsGridFunction.Tables[0].Rows[i]["ProcessName"].ToString();
                    chk.EnableViewState = false;
                    ChkProcessRoute.Items.Add(chk);
    
                }
    
                DataSet dsChkProcess = objBLLFabricInwardDetails.GetProcessRoute(objGridBind);
                for (int Counter = 0; Counter < dsChkProcess.Tables[0].Rows.Count; Counter++)
                {
                    if (dsChkProcess.Tables[0].Rows[Counter]["Checked"].ToString() == "1")
                    {
                        ChkProcessRoute.Items[Counter].Checked = true;
                    }
                    else
                    {
                        ChkProcessRoute.Items[Counter].Checked = false;
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
    
            }
    
    
     protected void BtnFabInwAddClick(object sender, AjaxEventArgs e)
        {
               ...
               string Lstr = string.Empty;
                for (int i = 0; i < ChkProcessRoute.Items.Count; i++)
                {
                    if (ChkProcessRoute.Items[i].Checked == true)
                    {
                        Lstr += ChkProcessRoute.Items[i].Value + ",";
                    }
                }
                ...
              objBLLFabricInwardDetails.InsertFabricInwardDetails(objBOFabricInwardDetails, Lstr);
                ...
    
        }
    
    
    <!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head runat="server"> 
        <title>Coolite Toolkit Example</title> 
    </head> 
    <body> 
        <form runat="server"> 
        <div>
      <ext:ScriptManager ID="ScriptManager1" runat="server" AjaxViewStateMode="Include"
                EnableViewState="true">
            </ext:ScriptManager>
    <ext:CheckboxGroup ID="ChkProcessRoute" runat="server" ColumnsNumber="5" Vertical="true"
                                                                Width="650" EnableViewState="true" LabelSeparator="">
     </ext:CheckboxGroup>
  6. #6
    Quote Originally Posted by Daniil View Post
    Hello!

    Could you clarify where the code that producing an error is placed? I supposed it's in a handler of AjaxEvent, right?
    Is there a condition like
    if (!Ext.IsAjaxRequest)
    { 
    //Creating CheckboxGroup's items
    }
    in the Page_Load?

    If so, it needs to remove this if you want to handle the CheckboxGroup's items on server side. In other words these items must be recreated during each ajax request. There is the same situation with the isPostBack condition.
    Please note that there is the same situation with the isPostBack condition.
    Just remove this from the Page_Load
    if (!IsPostBack)

Similar Threads

  1. [CLOSED] How to read Store in code behind?
    By rnachman in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Jun 14, 2011, 9:32 PM
  2. [CLOSED] [1.0] Dynamically load checkbox in Checkbox Group
    By vali1993 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jun 14, 2010, 5:05 PM
  3. [CLOSED] Adding Checkbox items to checkbox group during a postback?
    By vedagopal2004 in forum 1.x Legacy Premium Help
    Replies: 19
    Last Post: Feb 05, 2010, 10:13 AM
  4. Debugged code is read only
    By Nime in forum 1.x Help
    Replies: 0
    Last Post: Nov 09, 2009, 4:48 AM
  5. [CLOSED] Can't read value from disabled checkbox
    By Pablo in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jul 02, 2009, 2:05 PM

Tags for this Thread

Posting Permissions