473,734 Members | 2,798 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

datagrid and checkbox and confirm dialog

Hi All,

I have the following situation and am looking for answer in C#.

I have a datagrid and putting checkbox next to each record. In the
header I have a Delete button.

I want users to checkchekboxes and click the Delete button. That will
show a confirmation dialog message with the items they choose to
delete.

I have spent hours in the groups to find the similar one but without
any luck.
Here is the snippet of my code in page.aspx. The name (or id) of the
datagrid is BoreHolesResult . I will be updating based on the selected
checkbox and this checkbox should relate to the field Bore_Id.
<asp:TemplateCo lumn HeaderText="Typ e" >
<ItemTemplate >
<asp:TextBox ID="txtType" Runat="server" text='<
%#DataBinder.Ev al(Container.Da taItem, "BORE_TYPE" ) %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn>
<HeaderTemplate >
<asp:Button ID="btnDeleteBo reId" Runat="server" Text="Delete"
Onclick="Delete BoreID"></asp:Button>
</HeaderTemplate>
<ItemTemplate >
<center>
<asp:CheckBox ID='chkDelete' Runat="server">
</asp:CheckBox>
</center>
</ItemTemplate>
</asp:TemplateCol umn>
In the code file (page.aspx.cs),
I have the following:
public void DeleteBoreID(ob ject sender, System.EventArg s e)
{
string BoreID;
foreach (DataGridItem GridItem in BoreHolesResult .Items)
{
CheckBox myCheckbox =
(CheckBox)GridI tem.Cells[8].Controls[1];
if (myCheckbox.Che cked == true)
{
BoreID = GridItem.Cells[0].Text;
//here I want to show the confirm message with the
selected Bore Ids
// Cells[8] where the checkboxes are located in the datagrid 9th
item
//after confirm I will perform the delete records here.

}
}

}
I will highly appreciate your help. Thanks a million in advance.

best regards,
mamun

Feb 15 '07 #1
4 7501
On Feb 15, 1:32 pm, "mamun" <mamun...@hotma il.comwrote:
Hi All,

I have the following situation and am looking for answer in C#.

I have a datagrid and putting checkbox next to each record. In the
header I have a Delete button.

I want users to checkchekboxes and click the Delete button. That will
show a confirmation dialog message with the items they choose to
delete.

I have spent hours in the groups to find the similar one but without
any luck.

Here is the snippet of my code in page.aspx. The name (or id) of the
datagrid is BoreHolesResult . I will be updating based on the selected
checkbox and this checkbox should relate to the field Bore_Id.

<asp:TemplateCo lumn HeaderText="Typ e" >
<ItemTemplate >
<asp:TextBox ID="txtType" Runat="server" text='<
%#DataBinder.Ev al(Container.Da taItem, "BORE_TYPE" ) %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateCol umn>

<asp:TemplateCo lumn>
<HeaderTemplate >
<asp:Button ID="btnDeleteBo reId" Runat="server" Text="Delete"
Onclick="Delete BoreID"></asp:Button>
</HeaderTemplate>
<ItemTemplate >
<center>
<asp:CheckBox ID='chkDelete' Runat="server">
</asp:CheckBox>
</center>
</ItemTemplate>
</asp:TemplateCol umn>

In the code file (page.aspx.cs),

I have the following:

public void DeleteBoreID(ob ject sender, System.EventArg s e)
{
string BoreID;
foreach (DataGridItem GridItem in BoreHolesResult .Items)
{
CheckBox myCheckbox =
(CheckBox)GridI tem.Cells[8].Controls[1];
if (myCheckbox.Che cked == true)
{
BoreID = GridItem.Cells[0].Text;
//here I want to show the confirm message with the
selected Bore Ids
// Cells[8] where the checkboxes are located in the datagrid 9th
item
//after confirm I will perform the delete records here.

}
}

}

I will highly appreciate your help. Thanks a million in advance.

best regards,
mamun
Almost there. What happen here in your code is you want the backend
server code to display a message to the client prior to it executing.
Not possible. What you'll need is to fire the client code first, then
trigger the server code (function DeleteBoreID). To do this, you'll
need a javascript function to do the confirmation, then based on this
result, return false (cancel executing the server code) or return true
(proceed executing the server code).

I won't go into details of changing your code due to time constraint,
but the idea is as followed. In your Page_Load function, add the
following line:

protected override void Page_Load(objec t sender, EventArgs e)
{
....
//Ties javascript to button DeleteBoreId. When it is pressed, the
confirm fires first,
// if it returns true, then server code DeleteBoreID will get
triggered
btnDeleteBoreId .Attributes.Add ("onclick", "javascript:ret urn
confirmDeletion ('Are you sure you would like to remove the selected
items?');");
....
}

I think that's all.

Quoc Linh

Feb 15 '07 #2
On Feb 15, 2:28 pm, "Quoc Linh" <lequocl...@yah oo.comwrote:
On Feb 15, 1:32 pm, "mamun" <mamun...@hotma il.comwrote:
Hi All,
I have the following situation and am looking for answer in C#.
I have a datagrid and putting checkbox next to each record. In the
header I have a Delete button.
I want users to checkchekboxes and click the Delete button. That will
show a confirmation dialog message with the items they choose to
delete.
I have spent hours in the groups to find the similar one but without
any luck.
Here is the snippet of my code in page.aspx. The name (or id) of the
datagrid is BoreHolesResult . I will be updating based on the selected
checkbox and this checkbox should relate to the field Bore_Id.
<asp:TemplateCo lumn HeaderText="Typ e" >
<ItemTemplate >
<asp:TextBox ID="txtType" Runat="server" text='<
%#DataBinder.Ev al(Container.Da taItem, "BORE_TYPE" ) %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn>
<HeaderTemplate >
<asp:Button ID="btnDeleteBo reId" Runat="server" Text="Delete"
Onclick="Delete BoreID"></asp:Button>
</HeaderTemplate>
<ItemTemplate >
<center>
<asp:CheckBox ID='chkDelete' Runat="server">
</asp:CheckBox>
</center>
</ItemTemplate>
</asp:TemplateCol umn>
In the code file (page.aspx.cs),
I have the following:
public void DeleteBoreID(ob ject sender, System.EventArg s e)
{
string BoreID;
foreach (DataGridItem GridItem in BoreHolesResult .Items)
{
CheckBox myCheckbox =
(CheckBox)GridI tem.Cells[8].Controls[1];
if (myCheckbox.Che cked == true)
{
BoreID = GridItem.Cells[0].Text;
//here I want to show the confirm message with the
selected Bore Ids
// Cells[8] where the checkboxes are located in the datagrid 9th
item
//after confirm I will perform the delete records here.
}
}
}
I will highly appreciate your help. Thanks a million in advance.
best regards,
mamun

Almost there. What happen here in your code is you want the backend
server code to display a message to the client prior to it executing.
Not possible. What you'll need is to fire the client code first, then
trigger the server code (function DeleteBoreID). To do this, you'll
need a javascript function to do the confirmation, then based on this
result, return false (cancel executing the server code) or return true
(proceed executing the server code).

I won't go into details of changing your code due to time constraint,
but the idea is as followed. In your Page_Load function, add the
following line:

protected override void Page_Load(objec t sender, EventArgs e)
{
...
//Ties javascript to button DeleteBoreId. When it is pressed, the
confirm fires first,
// if it returns true, then server code DeleteBoreID will get
triggered
btnDeleteBoreId .Attributes.Add ("onclick", "javascript:ret urn
confirmDeletion ('Are you sure you would like to remove the selected
items?');");
...

}

I think that's all.

Quoc Linh
Ah, typo:

return confirmDeletion ('Are you sure you would like to remove the
selected
items?');");

should be:

return confirm('Are you sure you would like to remove the selected
items?');");

Quoc Linh

Feb 15 '07 #3
Hi Quoc Linh,

Thanks for replying.

Actually, I wanted client side validation and I changed according to
your suggestion but that did not help.

I would highly appreciate if you know any different way of doing this.
The main objective is users will select the checkboxes and the confirm
dialog box will show what records were selected (here is the bore_id
field) and if press yes then that will perform the delete query.

Many thanks

mamun

On Feb 15, 2:33 pm, "Quoc Linh" <lequocl...@yah oo.comwrote:
On Feb 15, 2:28 pm, "Quoc Linh" <lequocl...@yah oo.comwrote:


On Feb 15, 1:32 pm, "mamun" <mamun...@hotma il.comwrote:
Hi All,
I have the following situation and am looking for answer in C#.
I have a datagrid and putting checkbox next to each record. In the
header I have a Delete button.
I want users to checkchekboxes and click the Delete button. That will
show a confirmation dialog message with the items they choose to
delete.
I have spent hours in the groups to find the similar one but without
any luck.
Here is the snippet of my code in page.aspx. The name (or id) of the
datagrid is BoreHolesResult . I will be updating based on the selected
checkbox and this checkbox should relate to the field Bore_Id.
<asp:TemplateCo lumn HeaderText="Typ e" >
<ItemTemplate >
<asp:TextBox ID="txtType" Runat="server" text='<
%#DataBinder.Ev al(Container.Da taItem, "BORE_TYPE" ) %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn>
<HeaderTemplate >
<asp:Button ID="btnDeleteBo reId" Runat="server" Text="Delete"
Onclick="Delete BoreID"></asp:Button>
</HeaderTemplate>
<ItemTemplate >
<center>
<asp:CheckBox ID='chkDelete' Runat="server">
</asp:CheckBox>
</center>
</ItemTemplate>
</asp:TemplateCol umn>
In the code file (page.aspx.cs),
I have the following:
public void DeleteBoreID(ob ject sender, System.EventArg s e)
{
string BoreID;
foreach (DataGridItem GridItem in BoreHolesResult .Items)
{
CheckBox myCheckbox =
(CheckBox)GridI tem.Cells[8].Controls[1];
if (myCheckbox.Che cked == true)
{
BoreID = GridItem.Cells[0].Text;
//here I want to show the confirm message with the
selected Bore Ids
// Cells[8] where the checkboxes are located in the datagrid 9th
item
//after confirm I will perform the delete records here.
}
}
}
I will highly appreciate your help. Thanks a million in advance.
best regards,
mamun
Almost there. What happen here in your code is you want the backend
server code to display a message to the client prior to it executing.
Not possible. What you'll need is to fire the client code first, then
trigger the server code (function DeleteBoreID). To do this, you'll
need a javascript function to do the confirmation, then based on this
result, return false (cancel executing the server code) or return true
(proceed executing the server code).
I won't go into details of changing your code due to time constraint,
but the idea is as followed. In your Page_Load function, add the
following line:
protected override void Page_Load(objec t sender, EventArgs e)
{
...
//Ties javascript to button DeleteBoreId. When it is pressed, the
confirm fires first,
// if it returns true, then server code DeleteBoreID will get
triggered
btnDeleteBoreId .Attributes.Add ("onclick", "javascript:ret urn
confirmDeletion ('Are you sure you would like to remove the selected
items?');");
...
}
I think that's all.
Quoc Linh

Ah, typo:

return confirmDeletion ('Are you sure you would like to remove the
selected
items?');");

should be:

return confirm('Are you sure you would like to remove the selected
items?');");

Quoc Linh- Hide quoted text -

- Show quoted text -

Feb 15 '07 #4
On Feb 15, 3:34 pm, "mamun" <mamun...@hotma il.comwrote:
Hi Quoc Linh,

Thanks for replying.

Actually, I wanted client side validation and I changed according to
your suggestion but that did not help.

I would highly appreciate if you know any different way of doing this.
The main objective is users will select the checkboxes and the confirm
dialog box will show what records were selected (here is the bore_id
field) and if press yes then that will perform the delete query.

Many thanks

mamun

On Feb 15, 2:33 pm, "Quoc Linh" <lequocl...@yah oo.comwrote:
On Feb 15, 2:28 pm, "Quoc Linh" <lequocl...@yah oo.comwrote:
On Feb 15, 1:32 pm, "mamun" <mamun...@hotma il.comwrote:
Hi All,
I have the following situation and am looking for answer in C#.
I have a datagrid and putting checkbox next to each record. In the
header I have a Delete button.
I want users to checkchekboxes and click the Delete button. That will
show a confirmation dialog message with the items they choose to
delete.
I have spent hours in the groups to find the similar one but without
any luck.
Here is the snippet of my code in page.aspx. The name (or id) of the
datagrid is BoreHolesResult . I will be updating based on the selected
checkbox and this checkbox should relate to the field Bore_Id.
<asp:TemplateCo lumn HeaderText="Typ e" >
<ItemTemplate >
<asp:TextBox ID="txtType" Runat="server" text='<
%#DataBinder.Ev al(Container.Da taItem, "BORE_TYPE" ) %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn>
<HeaderTemplate >
<asp:Button ID="btnDeleteBo reId" Runat="server" Text="Delete"
Onclick="Delete BoreID"></asp:Button>
</HeaderTemplate>
<ItemTemplate >
<center>
<asp:CheckBox ID='chkDelete' Runat="server">
</asp:CheckBox>
</center>
</ItemTemplate>
</asp:TemplateCol umn>
In the code file (page.aspx.cs),
I have the following:
public void DeleteBoreID(ob ject sender, System.EventArg s e)
{
string BoreID;
foreach (DataGridItem GridItem in BoreHolesResult .Items)
{
CheckBox myCheckbox =
(CheckBox)GridI tem.Cells[8].Controls[1];
if (myCheckbox.Che cked == true)
{
BoreID = GridItem.Cells[0].Text;
//here I want to show the confirm message with the
selected Bore Ids
// Cells[8] where the checkboxes are located in the datagrid 9th
item
//after confirm I will perform the delete records here.
}
}
}
I will highly appreciate your help. Thanks a million in advance.
best regards,
mamun
Almost there. What happen here in your code is you want the backend
server code to display a message to the client prior to it executing.
Not possible. What you'll need is to fire the client code first, then
trigger the server code (function DeleteBoreID). To do this, you'll
need a javascript function to do the confirmation, then based on this
result, return false (cancel executing the server code) or return true
(proceed executing the server code).
I won't go into details of changing your code due to time constraint,
but the idea is as followed. In your Page_Load function, add the
following line:
protected override void Page_Load(objec t sender, EventArgs e)
{
...
//Ties javascript to button DeleteBoreId. When it is pressed, the
confirm fires first,
// if it returns true, then server code DeleteBoreID will get
triggered
btnDeleteBoreId .Attributes.Add ("onclick", "javascript:ret urn
confirmDeletion ('Are you sure you would like to remove the selected
items?');");
...
}
I think that's all.
Quoc Linh
Ah, typo:
return confirmDeletion ('Are you sure you would like to remove the
selected
items?');");
should be:
return confirm('Are you sure you would like to remove the selected
items?');");
Quoc Linh- Hide quoted text -
- Show quoted text -
Using the way I proposed earlier, you should be able to achieve:
User are able to check the checkboxes, then when click the delete
button, user receives a generic deletion confirmation message. If
user choose Yes, a post-back occurs, and the server will perform the
deletion. Is this correct?

If I understand you correctly, you now want the confirm dialog to
contain the description of the items you'd like to delete. To do
this, it is more tricky.

There are 3 ways I know of:

1. Same principal as I showed you, but replace the confirm("")
function with a Javascript function. Code the javascript function to
loop through your grid (rendered as html table), for each item, get
the checkbox values, build a string, and display a confirmed dialog
box. Return true/false in this function (same principal as the way I
showed you earlier)

2. Use Ajax.
As user clicks the checkbox, keep track of the checkbox states on the
server side.
As user clicked the button, use the server code to build the string,
then display at the client side.

I hear good comments about this one: http://www.ajaxpro.info/

3. Use Remote scripting. The predecessor of Ajax.
Here's a convenient tool to do it: http://www.codeproject.com/aspnet/
AlvaroRemoteScr ipting.asp

HTH,
Quoc Linh

Feb 16 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
11692
by: Homa | last post by:
Hi, I have a Datagrid that uses as a shopping cart and have a checkbox template column in it. I can't add both OnCheckedChanged Event and onclick client script for it. I want to do two things: 1. I want the checkbox fires CheckedChanged event. I did this as
8
1955
by: Inigo Jimenez | last post by:
I have an ASP .net web application installed in a Windows 2003 server. This web application has a webform that has a Datagrid. This Datagrid is filled with the data of a SQL table. I have a button that inserts a new row in the SQL table and then refresh the datagrid.
2
2100
by: Patrick Delifer | last post by:
Hi, I am trying to implement a JS confirm dialog when a user is deleting something off my Datagrid. The problem is that I don't have a Delete button in which case I could write the following function: btnDelete.Attributes.Add("onClick", "if(confirm('Are you sure you want to delete this order?')){}else{return false}");
1
3779
by: Harry Devine | last post by:
I have a DataGrid that is configured to use the Edit/Update/Cancel concept correctly. My grid shows values from 5 database fields. I only need to update that last 4 fields. The last field is a Yes/No value in Access. Using the OleDbCommand, if I do not consider the Yes/No field, the ExecuteNonQuery command, using my UPDATE SQL statement, updates the record correctly. However, if I put the Yes/No field into the mix, ExecuteNonQuery...
2
2436
by: Bob Hollness | last post by:
Hi group. I am a newbie to ASP.NET as you will see from some of the questions I may ask! I have a datagrid which I have populated from a database. It works great! I have added a column, via the Columns dialog box from the properties of the datagrid, on the left that contains a select button. So now, when you press the button the whole row is highlighted. Now, what I want to do is have the user highlight as many rows as they wish...
4
6946
by: rkbnair | last post by:
Is there any way to display an image button instead of the traditional Edit/Update/Cancel push button in a datagrid (with bound data)?
6
4638
by: JenHu | last post by:
Hi experts, I want to add a delete button in my datagrid, and before it deletes from database, I want to have a confirm dialog box for this deletion. I am entry level to the vb.net, and don't know java or c#. The problem is, when I tested the program, there is no pop-up confirmation box for the deletion, can you show me what' wrong with this code? Thank you.
0
1424
by: js | last post by:
I have a DataGrid with a command button on the first column of the DataGrid. The DataGrid is databound to a dataset with DataKeyFiled bound to "ControlNumber" field in the dataset. I am trying to save the row's ControlNumber to a page level variable when the corresponding item command is clicked . However, no matter what I do, the page property is alway blank. I also tried use CheckBox in the ItemTemplate. The CheckBox's...
1
2714
by: pleaseexplaintome | last post by:
I have a datagrid with checkboxes and I can check/uncheck the checkboxes to update a database by calling my oncheckchanged function. I would like to add popup asking the users if they are sure they want to proceed. I have written a javascript function named confirm_duplicate and it works as expected - it checks/unchecks checkboxes depending on user response.
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9449
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9236
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.