473,417 Members | 1,477 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,417 software developers and data experts.

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:TemplateColumn HeaderText="Type" >
<ItemTemplate>
<asp:TextBox ID="txtType" Runat="server" text='<
%#DataBinder.Eval(Container.DataItem, "BORE_TYPE") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<HeaderTemplate>
<asp:Button ID="btnDeleteBoreId" Runat="server" Text="Delete"
Onclick="DeleteBoreID"></asp:Button>
</HeaderTemplate>
<ItemTemplate>
<center>
<asp:CheckBox ID='chkDelete' Runat="server">
</asp:CheckBox>
</center>
</ItemTemplate>
</asp:TemplateColumn>
In the code file (page.aspx.cs),
I have the following:
public void DeleteBoreID(object sender, System.EventArgs e)
{
string BoreID;
foreach (DataGridItem GridItem in BoreHolesResult.Items)
{
CheckBox myCheckbox =
(CheckBox)GridItem.Cells[8].Controls[1];
if (myCheckbox.Checked == 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 7474
On Feb 15, 1:32 pm, "mamun" <mamun...@hotmail.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:TemplateColumn HeaderText="Type" >
<ItemTemplate>
<asp:TextBox ID="txtType" Runat="server" text='<
%#DataBinder.Eval(Container.DataItem, "BORE_TYPE") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>

<asp:TemplateColumn>
<HeaderTemplate>
<asp:Button ID="btnDeleteBoreId" Runat="server" Text="Delete"
Onclick="DeleteBoreID"></asp:Button>
</HeaderTemplate>
<ItemTemplate>
<center>
<asp:CheckBox ID='chkDelete' Runat="server">
</asp:CheckBox>
</center>
</ItemTemplate>
</asp:TemplateColumn>

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

I have the following:

public void DeleteBoreID(object sender, System.EventArgs e)
{
string BoreID;
foreach (DataGridItem GridItem in BoreHolesResult.Items)
{
CheckBox myCheckbox =
(CheckBox)GridItem.Cells[8].Controls[1];
if (myCheckbox.Checked == 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(object 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:return
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...@yahoo.comwrote:
On Feb 15, 1:32 pm, "mamun" <mamun...@hotmail.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:TemplateColumn HeaderText="Type" >
<ItemTemplate>
<asp:TextBox ID="txtType" Runat="server" text='<
%#DataBinder.Eval(Container.DataItem, "BORE_TYPE") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<HeaderTemplate>
<asp:Button ID="btnDeleteBoreId" Runat="server" Text="Delete"
Onclick="DeleteBoreID"></asp:Button>
</HeaderTemplate>
<ItemTemplate>
<center>
<asp:CheckBox ID='chkDelete' Runat="server">
</asp:CheckBox>
</center>
</ItemTemplate>
</asp:TemplateColumn>
In the code file (page.aspx.cs),
I have the following:
public void DeleteBoreID(object sender, System.EventArgs e)
{
string BoreID;
foreach (DataGridItem GridItem in BoreHolesResult.Items)
{
CheckBox myCheckbox =
(CheckBox)GridItem.Cells[8].Controls[1];
if (myCheckbox.Checked == 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(object 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:return
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...@yahoo.comwrote:
On Feb 15, 2:28 pm, "Quoc Linh" <lequocl...@yahoo.comwrote:


On Feb 15, 1:32 pm, "mamun" <mamun...@hotmail.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:TemplateColumn HeaderText="Type" >
<ItemTemplate>
<asp:TextBox ID="txtType" Runat="server" text='<
%#DataBinder.Eval(Container.DataItem, "BORE_TYPE") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<HeaderTemplate>
<asp:Button ID="btnDeleteBoreId" Runat="server" Text="Delete"
Onclick="DeleteBoreID"></asp:Button>
</HeaderTemplate>
<ItemTemplate>
<center>
<asp:CheckBox ID='chkDelete' Runat="server">
</asp:CheckBox>
</center>
</ItemTemplate>
</asp:TemplateColumn>
In the code file (page.aspx.cs),
I have the following:
public void DeleteBoreID(object sender, System.EventArgs e)
{
string BoreID;
foreach (DataGridItem GridItem in BoreHolesResult.Items)
{
CheckBox myCheckbox =
(CheckBox)GridItem.Cells[8].Controls[1];
if (myCheckbox.Checked == 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(object 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:return
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...@hotmail.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...@yahoo.comwrote:
On Feb 15, 2:28 pm, "Quoc Linh" <lequocl...@yahoo.comwrote:
On Feb 15, 1:32 pm, "mamun" <mamun...@hotmail.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:TemplateColumn HeaderText="Type" >
<ItemTemplate>
<asp:TextBox ID="txtType" Runat="server" text='<
%#DataBinder.Eval(Container.DataItem, "BORE_TYPE") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<HeaderTemplate>
<asp:Button ID="btnDeleteBoreId" Runat="server" Text="Delete"
Onclick="DeleteBoreID"></asp:Button>
</HeaderTemplate>
<ItemTemplate>
<center>
<asp:CheckBox ID='chkDelete' Runat="server">
</asp:CheckBox>
</center>
</ItemTemplate>
</asp:TemplateColumn>
In the code file (page.aspx.cs),
I have the following:
public void DeleteBoreID(object sender, System.EventArgs e)
{
string BoreID;
foreach (DataGridItem GridItem in BoreHolesResult.Items)
{
CheckBox myCheckbox =
(CheckBox)GridItem.Cells[8].Controls[1];
if (myCheckbox.Checked == 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(object 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:return
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/
AlvaroRemoteScripting.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
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...
8
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...
2
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...
1
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...
2
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...
4
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
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...
0
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...
1
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
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,...
0
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...

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.