Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

More on the datagrid moving data between the two...

  Asked By: Robert    Date: Apr 17    Category: Asp.net    Views: 5495
  

I'm building my
first .NET application with the IE webcontrols (tabstrip and
multipage) and some datagrids. :-P

I'm a newbie to ASP.NET but I think I'm catching on. I've been
doing ASP way too long (since the beta days) and it's about time I
switched to an object-oriented coding language.

Share: 

 

5 Answers Found

 
Answer #1    Answered By: Roosevelt Jenkins     Answered On: Apr 17

To move your selections to another grid you'd have to use jscript.

You'de have to have way of generating that jscript from the web page as it would
likely need to have an idea of what the controls were called in the datagrid.
The web page will generate an ID for the controls in the datagrid  ... so you
have to have a way of storing them client side in arrays to enable your
javascript to work.

Or .... just have a button or link in your first dg that calls a jscript
function with written param of the text box id's .... and the other dg that is
to recieve the choices - well the best think to do would be to have it identical
to the first grid, that way you could simply replace a part of the string in the
mentioned function and it will make the placement.

You just nee to generate the script to do it from the server, thus enabling you
to pass the correct params in the client functions that will do the work.

I wouldn't use checkboxes, I'd add a hyperlink which calls a function to make
the move, one for each row.

The html would look something like the following ... noting that all id's will
be generated by asp.NET so you need to be able to get their id's and write them
straight into your href links.


<script>
function movedata(d) {
var d2;
//.... parse d and replace dg2 with dg1 and assign to d2
var t1;
var t2;
t1 = document.forms[0].getElementById("d");
t2 = document.forms[0].getElementById("d2");
t1.Text = t2.Text;
t2.Text = ""; // perhaps
}


</script>

< input type=Text id=dg1_ctl0__ctl0>
< input type=Text id=dg1_ctl0__ctl1>
< input type=Text id=dg1_ctl0__ctl2>
< input type=Text id=dg1_ctl0__ctl3>


< input type=Text id=dg2_ctl0__ctl0><a href="javascript:void(0)"
onclick="movedata('dg2_ctl0__ctl0')>Move Data</a>
< input type=Text id=dg2_ctl0__ctl1>><a href="javascript:void(0)"
onclick="movedata('dg2_ctl0__ctl1')>Move Data</a>
< input type=Text id=dg2_ctl0__ctl2>><a href="javascript:void(0)"
onclick="movedata('dg2_ctl0__ctl2')>Move Data</a>
< input type=Text id=dg3_ctl0__ctl3>><a href="javascript:void(0)"
onclick="movedata('dg2_ctl0__ctl3')>Move Data</a>

 
Answer #2    Answered By: Rosie Hughes     Answered On: Apr 17

Closest thing I've ever done is move Items back and forth between ListBoxes.
Doing that with a DG **should** be possible, but I wouldn't try it without a
serious paycheck coming at the end of the week. Just thinking about all the
JS code you'd need is giving me a head-ache. lol Not to mention
ViewState concerns on PostBack.

 
Answer #3    Answered By: Freya Brown     Answered On: Apr 17

It doesn't have to happen client-side. I can have a postback if
that helps any. I might've not been clear when I meant "move" from
one to another.

 
Answer #4    Answered By: Dep Tran     Answered On: Apr 17

Then you got the problem of getting those values of the grid server side.

Maybe easy maybe not ?

You'll have to play with Edit_Item and Update_Item and if your sneay you can
access the controls in Item_Select using control collection.

 
Answer #5    Answered By: Cesara Fernandez     Answered On: Apr 17

If it doesn't have to be clientside then its easy isn't it ?

You just post back with the checkboxes, grab the data  and fill the other datgrid
with that data.

Trouble would be that you need to alter data in the select mode of datgrid, i.e.
the checkboxes. But it can be done using control collection of datgrid within
the Item_Select ( I think!)

foreach (Control c in Datagrid1.Controls[x].Controls)
{
Response.Write(c.GetType());
}

where x starts at 1 and and at number if items in grid-1.

or use an if control == checkbox

or use loop loop.

Bit of messing should sort it.

Or use edit item to ... but that requires a postback each time  you check a box.

 
Didn't find what you were looking for? Find more on More on the datagrid moving data between the two... Or get search suggestion and latest updates.




Tagged: