PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

datagrid and checkbox and confirm dialog

 
 
mamun
Guest
Posts: n/a
 
      15th Feb 2007
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

 
Reply With Quote
 
 
 
 
Quoc Linh
Guest
Posts: n/a
 
      15th Feb 2007
On Feb 15, 1:32 pm, "mamun" <mamun...@hotmail.com> wrote:
> 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

 
Reply With Quote
 
Quoc Linh
Guest
Posts: n/a
 
      15th Feb 2007
On Feb 15, 2:28 pm, "Quoc Linh" <lequocl...@yahoo.com> wrote:
> On Feb 15, 1:32 pm, "mamun" <mamun...@hotmail.com> wrote:
>
>
>
> > 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

 
Reply With Quote
 
mamun
Guest
Posts: n/a
 
      15th Feb 2007
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.com> wrote:
> On Feb 15, 2:28 pm, "Quoc Linh" <lequocl...@yahoo.com> wrote:
>
>
>
>
>
> > On Feb 15, 1:32 pm, "mamun" <mamun...@hotmail.com> wrote:

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



 
Reply With Quote
 
Quoc Linh
Guest
Posts: n/a
 
      15th Feb 2007
On Feb 15, 3:34 pm, "mamun" <mamun...@hotmail.com> wrote:
> 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.com> wrote:
>
> > On Feb 15, 2:28 pm, "Quoc Linh" <lequocl...@yahoo.com> wrote:

>
> > > On Feb 15, 1:32 pm, "mamun" <mamun...@hotmail.com> wrote:

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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying Dialog appears over Confirm File Replace dialog theclyde Windows Vista General Discussion 1 13th Jun 2007 12:16 AM
DataGrid and embeded Checkbox..How to find if checkbox clicked =?Utf-8?B?RG90TmV0RGV2?= Microsoft ASP .NET 1 6th Oct 2006 05:11 PM
checkBox and client confirm =?Utf-8?B?ZW56bw==?= Microsoft ASP .NET 3 11th Apr 2006 05:36 PM
Master-Detail Datagrid -checkbox (once tick the checkbox, all the child checkbox is ticked) Agnes Microsoft VB .NET 0 16th Aug 2004 11:23 AM
JS Confirm dialog from datagrid template column Patrick Delifer Microsoft ASP .NET 2 28th Apr 2004 07:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:13 PM.