Strong Coders Community

Where the extreme coders hang out.
Welcome to Strong Coders Community Sign in | Join | Help Messenger
in Search

data grid

Last post 01-30-2007, 1:17 PM by Dean Fiala . 3 replies.
Sort Posts: Previous Next
  •  01-28-2007, 9:09 PM 1679
    • datagridboy123 is not online. Last active: 02-02-2007, 11:42 AM datagridboy123
    • Top 10 Contributor
    • Joined on 11-04-2006
    • Posts 17
    • Points 380

    data grid

    Hi,

    I would like to add a column to this grid view with a check box. I've tried the below code but it only produces a single check box. I have a button 'Create a Order'. Before the user could proceed to the next page it should validate that the user has atleast selected one record from the grid before proceeding. Also, how do I save the checked data in a variable so I could print the results on the next page??

    Thanks for your help.

    <--form-->

    AutoGenerateColumns="true"
    AllowPaging="true"
    Pagesize="20"
    AllowSorting="true"
    DataKeyNames="Sku,Product_name,Supplier number"
    DataMember="DefaultView"
    DataSourceID="AccessDataSource1"
    ID="GridView1"
    runat="server" />


     
            Include?
           
                 
           

           


      
      
      

     
     


     


    • Post Points: 20
    • Alert the moderators
  •  01-30-2007, 7:17 AM 1685 in reply to 1679
    • Dean Fiala is not online. Last active: 02-11-2007, 6:10 PM Dean Fiala
    • Top 10 Contributor
    • Joined on 10-17-2006
    • Posts 49
    • Points 620
    • MicrosoftMVP Moderator StrongCoders

    Re: data grid

    >>I've tried the below code but it only produces a single check box.

    It produces one checkbox per row, do you want more? In what way?

     

    >>Before the user could proceed to the next page it should validate thatthe user has atleast selected one record from the grid beforeproceeding.

     

    In your command event handler call a method to read the user's selections.  If they haven't selected anything throw an error. Otherwise you can add the selected SKUs to a session variable which you can retrieve from the next page.

     

             ArrayList SelectedSKUs = GetSelectedSKUs();
            if (SelectedSKUs.Count > 0)
            {
                Session.Add("UserSelectedSKUs", SelectedSKUs);
            }
            else
            {
                //display an error
            }


    private ArrayList GetSelectedSKUs()
        {
            CheckBox RowCheckBox = null;
            ArrayList SelectedSKUs = new ArrayList();
            foreach (GridViewRow Row in GridView1.Rows)
            {
                RowCheckBox = (CheckBox)Row.FindControl("RowCheckBox");
                if (RowCheckBox.Checked)
                {
                    SelectedSKUs.Add(GridView1.DataKeys[Row.RowIndex]);

                }

            }

            return SelectedSKUs;
        }

     

     

     



    Dean Fiala
    Very Practical Software, Inc.
    Filed under:
    • Post Points: 20
    • Alert the moderators
  •  01-30-2007, 10:40 AM 1686 in reply to 1685
    • datagridboy123 is not online. Last active: 02-02-2007, 11:42 AM datagridboy123
    • Top 10 Contributor
    • Joined on 11-04-2006
    • Posts 17
    • Points 380

    Re: data grid

    Hi Dean, 

    It produces just one check box at the bottom of the grid view. I would like a check box per row in the grid view. Do you have any suggestions on ho I could do this.

    Thanks,
    Paras

    • Post Points: 20
    • Alert the moderators
  •  01-30-2007, 1:17 PM 1688 in reply to 1686
    • Dean Fiala is not online. Last active: 02-11-2007, 6:10 PM Dean Fiala
    • Top 10 Contributor
    • Joined on 10-17-2006
    • Posts 49
    • Points 620
    • MicrosoftMVP Moderator StrongCoders

    Re: data grid

    Are you sure this your column defintition?

     
     
            Include?
           
                 
           

     

     

    Because, as you notice, the check box is in the Item template, which means it will show up in every row in the gridview. 

    If it is not, it is because:

    a) you do not have the checkbox in the ItemTemplate

    b) you have two gridviews on the page, the checkbox is in a gridview that is only showing in one row.
     


    Dean Fiala
    Very Practical Software, Inc.
    • Post Points: 5
    • Alert the moderators

Powered by Community Server (Commercial Edition), by Telligent Systems