 |
| 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
|
|
|
|

May 11th, 2004, 06:06 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 146
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

May 11th, 2004, 08:46 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 146
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

May 11th, 2004, 09:20 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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.
|
|

May 11th, 2004, 10:06 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 146
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

May 11th, 2004, 10:23 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 146
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

May 11th, 2004, 11:54 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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.
|
|

May 13th, 2004, 02:37 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 146
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Dear Imar,
thanks for the code, yeah man I did it,
did the job
cheers matey!
Adz - The World is not enough
|
|
 |