Help with this

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • momo

    Help with this

    Hello all,

    I need help with this. I have a datagrid (dg1) with checkboxes and I want
    when some rows are selected to populate another datagrid (dg2) with the
    selected rows from (dg1).

    Thanks

    Momo


  • Alvin Bruney

    #2
    Re: Help with this

    What you need to do here is (or at least one approach) to retrieve the
    checkboxes from the datagrid. Here it depends on how you added them and how
    you designed your system. By far the easiest solution to implement depends
    on whether or not you have a primary key set up in your database. If you do,
    then you

    --
    Regards,
    Alvin Bruney
    Got tidbits? Get it here...

    "momo" <searchengine@s eeourweb.com> wrote in message
    news:OGg8M%2380 DHA.1272@TK2MSF TNGP12.phx.gbl. ..[color=blue]
    > Hello all,
    >
    > I need help with this. I have a datagrid (dg1) with checkboxes and I want
    > when some rows are selected to populate another datagrid (dg2) with the
    > selected rows from (dg1).
    >
    > Thanks
    >
    > Momo
    >
    >[/color]


    Comment

    • Alvin Bruney

      #3
      Re: Help with this

      Oops, wasnt done yet. If your database has a primary key, then you can use
      the datakeys object to loop thru and pick out your values of the row to
      which the check box is attached. You will find the check box normally from
      the request.forms object. this is totally dependent on how you added the
      check boxes in the first place. The datakeys option results in much less
      code than any other option i can think of.

      Another option is to loop thru the grid looking for a checked check box.
      You'd use the datagrid.items object to cycle thru in the loop construct
      retrieving the controls. For each control you find, you will cast to a check
      box object and then examine the checked property. If it is checked, you loop
      thru each cell of the cells object to retrieve the data. you will use that
      stored source to populate the new datagrid.

      There is another option. Use your first datagrid to find the index of the
      checked row, then go find that row in the underlying dataset. add that row
      to the dataset2 which forms the datasource of datagrid2. Then rebind. You
      need to add a new row, you can't just add a reference because a row must
      exist in exactly one dataset. If i've rambled on and on, ask me to clarify.
      or somebody else can.

      --
      Regards,
      Alvin Bruney
      Got tidbits? Get it here...

      "momo" <searchengine@s eeourweb.com> wrote in message
      news:OGg8M%2380 DHA.1272@TK2MSF TNGP12.phx.gbl. ..[color=blue]
      > Hello all,
      >
      > I need help with this. I have a datagrid (dg1) with checkboxes and I want
      > when some rows are selected to populate another datagrid (dg2) with the
      > selected rows from (dg1).
      >
      > Thanks
      >
      > Momo
      >
      >[/color]


      Comment

      • momo

        #4
        Re: Help with this

        Alvin,

        Will you please show me the code on how to do solution two and three.

        Thanks,

        Momo


        "Alvin Bruney" <vapor at steaming post office> wrote in message
        news:%23NAKLnA1 DHA.2448@TK2MSF TNGP12.phx.gbl. ..[color=blue]
        > Oops, wasnt done yet. If your database has a primary key, then you can use
        > the datakeys object to loop thru and pick out your values of the row to
        > which the check box is attached. You will find the check box normally from
        > the request.forms object. this is totally dependent on how you added the
        > check boxes in the first place. The datakeys option results in much less
        > code than any other option i can think of.
        >
        > Another option is to loop thru the grid looking for a checked check box.
        > You'd use the datagrid.items object to cycle thru in the loop construct
        > retrieving the controls. For each control you find, you will cast to a[/color]
        check[color=blue]
        > box object and then examine the checked property. If it is checked, you[/color]
        loop[color=blue]
        > thru each cell of the cells object to retrieve the data. you will use that
        > stored source to populate the new datagrid.
        >
        > There is another option. Use your first datagrid to find the index of the
        > checked row, then go find that row in the underlying dataset. add that row
        > to the dataset2 which forms the datasource of datagrid2. Then rebind. You
        > need to add a new row, you can't just add a reference because a row must
        > exist in exactly one dataset. If i've rambled on and on, ask me to[/color]
        clarify.[color=blue]
        > or somebody else can.
        >
        > --
        > Regards,
        > Alvin Bruney
        > Got tidbits? Get it here...
        > http://tinyurl.com/2bz4t
        > "momo" <searchengine@s eeourweb.com> wrote in message
        > news:OGg8M%2380 DHA.1272@TK2MSF TNGP12.phx.gbl. ..[color=green]
        > > Hello all,
        > >
        > > I need help with this. I have a datagrid (dg1) with checkboxes and I[/color][/color]
        want[color=blue][color=green]
        > > when some rows are selected to populate another datagrid (dg2) with the
        > > selected rows from (dg1).
        > >
        > > Thanks
        > >
        > > Momo
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Alvin Bruney

          #5
          Re: Help with this

          This code retrieves checked values of radiolist buttons embedded in the
          first column of a datagrid.
          Modify the following disparate snippets to suit your needs. They weren't all
          taken from the same application so it would need some minor modification,
          but the logic is what is important.

          //the radio buttons were added this way in the itemcreated event handler
          if(e.Item.ItemT ype == ListItemType.It em || e.Item.ItemType ==
          ListItemType.Al ternatingItem)

          {

          //column 1 is an itemtemplate column

          Label lbl = (Label)e.Item.F indControl("Dig ");

          if(lbl != null)

          lbl.Text = "<input type=radio name='samegroup ' value=" +
          e.Item.Cells[1].Text + ">";

          }

          //use this to retrieve the selected radio button in the entire grid thru the
          form object

          private string GetSelectedItem s()

          {

          //individual radiobuttons are tied together using samegroup

          string retval = Request.Form["samegroup"];

          if(retval == null || String.Empty == retval)

          Page.Controls.A dd(new LiteralControl( "<script>alert( 'Please select a row to
          dig on by enabling a radio button in the grid')</script>"));

          return retval;

          }



          //this code retrieves the row for the selected radio button

          ArrayList currentRow = new ArrayList();

          for(int i = 0; i < e.Item.Cells.Co unt; i++)

          currentRow.Add( e.Item.Cells[i].Text);

          ViewState["CURRENTROW "] = currentRow;

          //this code adds a new row to a dataset
          DataRow myRow = dsTemp.Tables[0].NewRow();

          //pull the values out of session current row and add to a new row then
          bind

          myRow[loopcount]= value;

          myRow[count + 2]= value2

          dsTemp.Tables[0].Rows.Add(myRow );

          //bind the result to the grid so that the new row can show up
          dg2.DataSource = dsTemp;
          dg2.DataBind();


          --
          Regards,
          Alvin Bruney
          Got tidbits? Get it here...

          "momo" <searchengine@s eeourweb.com> wrote in message
          news:eva8jrF1DH A.2948@TK2MSFTN GP09.phx.gbl...[color=blue]
          > Alvin,
          >
          > Will you please show me the code on how to do solution two and three.
          >
          > Thanks,
          >
          > Momo
          >
          >
          > "Alvin Bruney" <vapor at steaming post office> wrote in message
          > news:%23NAKLnA1 DHA.2448@TK2MSF TNGP12.phx.gbl. ..[color=green]
          > > Oops, wasnt done yet. If your database has a primary key, then you can[/color][/color]
          use[color=blue][color=green]
          > > the datakeys object to loop thru and pick out your values of the row to
          > > which the check box is attached. You will find the check box normally[/color][/color]
          from[color=blue][color=green]
          > > the request.forms object. this is totally dependent on how you added the
          > > check boxes in the first place. The datakeys option results in much less
          > > code than any other option i can think of.
          > >
          > > Another option is to loop thru the grid looking for a checked check box.
          > > You'd use the datagrid.items object to cycle thru in the loop construct
          > > retrieving the controls. For each control you find, you will cast to a[/color]
          > check[color=green]
          > > box object and then examine the checked property. If it is checked, you[/color]
          > loop[color=green]
          > > thru each cell of the cells object to retrieve the data. you will use[/color][/color]
          that[color=blue][color=green]
          > > stored source to populate the new datagrid.
          > >
          > > There is another option. Use your first datagrid to find the index of[/color][/color]
          the[color=blue][color=green]
          > > checked row, then go find that row in the underlying dataset. add that[/color][/color]
          row[color=blue][color=green]
          > > to the dataset2 which forms the datasource of datagrid2. Then rebind.[/color][/color]
          You[color=blue][color=green]
          > > need to add a new row, you can't just add a reference because a row must
          > > exist in exactly one dataset. If i've rambled on and on, ask me to[/color]
          > clarify.[color=green]
          > > or somebody else can.
          > >
          > > --
          > > Regards,
          > > Alvin Bruney
          > > Got tidbits? Get it here...
          > > http://tinyurl.com/2bz4t
          > > "momo" <searchengine@s eeourweb.com> wrote in message
          > > news:OGg8M%2380 DHA.1272@TK2MSF TNGP12.phx.gbl. ..[color=darkred]
          > > > Hello all,
          > > >
          > > > I need help with this. I have a datagrid (dg1) with checkboxes and I[/color][/color]
          > want[color=green][color=darkred]
          > > > when some rows are selected to populate another datagrid (dg2) with[/color][/color][/color]
          the[color=blue][color=green][color=darkred]
          > > > selected rows from (dg1).
          > > >
          > > > Thanks
          > > >
          > > > Momo
          > > >
          > > >[/color]
          > >
          > >[/color]
          >
          >[/color]


          Comment

          Working...