Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 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 May 11th, 2004, 06:06 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 146
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to aadz5
Default Checkbox in a datagrid

Dear Guys,

I have a data grid, there are various values in this grid. I have a templatecolumn which has a check box in it. When the checkbox is selected, I want the selected rows to be inserted into a table. is this possible?? I was going to use an external button and use its onclick to define which function is used.

Any Ideas??



Adz - The World is not enough
__________________
Adz - Learning The J2EE Ways.
 
Old May 11th, 2004, 08:46 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 146
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to aadz5
Default

Guys,

I have tried to code this,

Here is my code: -

private void SaveHouses(object sender, System.EventArgs e)
{
    foreach (DataGridItem item in dgHouse.Items)
    {
        CheckBox chkBox = (CheckBox)item.FindControl("cbSaveHouses");
        if (chkBox != null && chkBox.Checked)
        {
            string UserID = User.Identity.Name.ToString();
            string HouseID = ex.Item.Cells[0].ToString();

            string strConnection = "Provider = Microsoft.OleDb.Jet.4.0; Data Source = \\\\premfs3\\sites\\premium8\\adnanarab66\\databas e\\House.mdb;";
            OleDbConnection obj1Connection = new OleDbConnection(strConnection);

            string strInsert = "INSERT INTO HousesSearched (HouseID, UserID) VALUES (?, ?)";

            OleDbCommand objCommand = new OleDbCommand(strInsert, obj1Connection);

              objCommand.Parameters.Add("HouseID", OleDbType.VarChar, 32, "HouseID");
              objCommand.Parameters.Add("UserID", OleDbType.VarChar, 32, "UserID");

            objCommand.Parameters["HouseID"].Value = HouseID;
              objCommand.Parameters["UserID"].Value = UserID;
        }
    }
}

The problem is that the e.item.Cell[] requires the DataGridCommandEventArgs class and I cant implement both System.EventArgs and DataGridCommandEventArgs. Any ideas??

Adz - The World is not enough
 
Old May 11th, 2004, 09:20 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Adz,

What kind of Event is SaveHouses taking care off? Why does it need to have a signature of object/System.EventArgs??

Can't you have it accept an DataGridCommandEventArgs instance instead? That is, when it's somehow triggered by the DataGrid.

If that method is triggered by a button, you can't use e, but should use the Grid's item, just as you do with the FindControl method.

Wouldn't this:

string HouseID = item.Cells[0].ToString();

fix the problem? After all, item refers to the current DataGridItem being looped and will expose a Cells property, right??

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old May 11th, 2004, 10:06 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 146
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to aadz5
Default

Imar,

it is trigered by a button, and that why I have used system.eventargs, but saying that, why not use autopostback = true. Ok I will try this, thank man



Adz - The World is not enough
 
Old May 11th, 2004, 10:23 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 146
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to aadz5
Default

Imar,

I have just tried the autopostback = true; and also made the OnCheckedChange = "Function". The problem is, is that this also uses the system.eventargs e. I understand what you are say, is there a way around this??

Adz - The World is not enough
 
Old May 11th, 2004, 11:54 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Well, I think I gave the solution before:

Use System.EventArgs, and use item.Cells[0].ToString() instead if e.Item. Wouldn't that work??

E.g.:
Code:
foreach (DataGridItem myDataGridItem in dgHouse.Items)
{
  CheckBox chkBox = (CheckBox)item.FindControl("cbSaveHouses");
  if (chkBox != null && chkBox.Checked)
  {
    string UserID = User.Identity.Name.ToString();
    string HouseID = myDataGridItem.Cells[0].ToString();
    In this example, I used myDataGridItem to distinguish between a custom item and the Item item.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old May 13th, 2004, 02:37 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 146
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to aadz5
Default

Dear Imar,

thanks for the code, yeah man I did it,

did the job

cheers matey!

Adz - The World is not enough





Similar Threads
Thread Thread Starter Forum Replies Last Post
CheckBox in Datagrid sumith ASP.NET 1.0 and 1.1 Professional 1 March 21st, 2007 06:25 AM
checkbox in datagrid asad_prog VB.NET 0 November 25th, 2006 02:41 PM
CheckBox in DataGrid Baby_programmer ASP.NET 1.x and 2.0 Application Design 2 March 11th, 2005 12:42 AM
CheckBox in DataGrid Baby_programmer ASP.NET 1.0 and 1.1 Basics 1 March 3rd, 2005 08:33 PM
checkbox in datagrid joekske VB How-To 1 June 3rd, 2004 02:31 PM





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