i am using asp.net with oracle,now i am selecting the record [b]for example: table name emp it contains 50 records now display whole records in asp executing page each records end i am added checkbox control ,if i am choosing any one of the checkbox then press submit button that corresponding record want to delete based on the autoid.
this id field i am maintaining [ /B]
plz give solution
thank u
RAMANAN RAM
In the Button Click event, loop through all of the list items in the CheckBoxList and delete the corresponding record if it is selected.
Here's a working example.
The ASP markup code: -
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
-
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
<html xmlns="http://www.w3.org/1999/xhtml">
-
<head runat="server">
-
<title>Exploring</title>
-
</head>
-
<body>
-
<form id="form1" runat="server">
-
<div>
-
<asp:CheckBoxList ID="theCheckboxList" runat="server">
-
</asp:CheckBoxList>
-
<asp:Button ID="DeleteSelectedRecord" runat="server" OnClick="DeleteSelectedRecord_Click" Text="Delete Checked Items"/>
-
<asp:Button ID="ResetDataSource" runat="server" OnClick="ResetDataSource_Click" Text="Reset Data Source"/>
-
</div>
-
</form>
-
</body>
-
</html>
The C# code behind: -
using System;
-
using System.Collections.Generic;
-
using System.Linq;
-
using System.Web;
-
using System.Web.UI;
-
using System.Web.UI.WebControls;
-
-
namespace WebApplication1
-
{
-
public partial class WebForm1 : System.Web.UI.Page
-
{
-
/// <summary>
-
/// This property is used to get and set the source for the grid.
-
/// If there is not already a source stored in session, it creates one.
-
/// </summary>
-
private System.Data.DataTable Source
-
{
-
get
-
{
-
source = (System.Data.DataTable)Session["source"];
-
if (source == null)
-
{
-
source = new System.Data.DataTable();
-
source.Columns.Add(new System.Data.DataColumn("ID", typeof(int)));
-
source.Columns.Add(new System.Data.DataColumn("Name"));
-
for (int i = 0; i < 10; i++)
-
{
-
System.Data.DataRow dr = source.NewRow();
-
dr["ID"] = i;
-
dr["Name"] = String.Format("{0}{1}", "Name ", i + 1);
-
source.Rows.Add(dr);
-
}
-
Session["source"] = source;
-
-
}
-
return source;
-
}
-
set
-
{
-
source = value;
-
Session["source"] = source;
-
}
-
}
-
private System.Data.DataTable source;
-
-
-
protected void Page_Load(object sender, EventArgs e)
-
{ }
-
-
protected void DeleteSelectedRecord_Click(object sender, EventArgs e)
-
{
-
foreach (ListItem checkBoxListItem in theCheckboxList.Items)
-
{
-
-
if (checkBoxListItem.Selected)
-
{
-
int itemID;//Retrieving the item's ID
-
int.TryParse(checkBoxListItem.Value, out itemID);
-
-
//This is where you would update the database based on the record changed
-
//I'm not connected to a database so I am simply updating the in memory DataTable
-
string selectFilter = String.Format("{0}{1}{2}", "ID='", itemID, "'");//Used to retrieve the item checked from the source (DataTable) for the grid
-
System.Data.DataRow[] rows = Source.Select(selectFilter);//The rows that match the ID selected...this should be just 1 row.
-
if (rows.Length > 0)
-
rows[0].Delete();//here you would go to the database and delete the record
-
}
-
}
-
Source = source;//Saving the source for next time
-
}
-
-
protected void ResetDataSource_Click(object sender, EventArgs e)
-
{
-
Source = null;
-
}
-
-
void Page_PreRender(object sender, EventArgs e)
-
{
-
//Getting the source for the CheckBoxList and binding the CheckBoxList to the source.
-
theCheckboxList.DataSource = Source;
-
theCheckboxList.DataTextField = "Name";
-
theCheckboxList.DataValueField = "ID";
-
theCheckboxList.DataBind();
-
}
-
}
-
}
-Frinny
1 1800
In the Button Click event, loop through all of the list items in the CheckBoxList and delete the corresponding record if it is selected.
Here's a working example.
The ASP markup code: -
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
-
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
<html xmlns="http://www.w3.org/1999/xhtml">
-
<head runat="server">
-
<title>Exploring</title>
-
</head>
-
<body>
-
<form id="form1" runat="server">
-
<div>
-
<asp:CheckBoxList ID="theCheckboxList" runat="server">
-
</asp:CheckBoxList>
-
<asp:Button ID="DeleteSelectedRecord" runat="server" OnClick="DeleteSelectedRecord_Click" Text="Delete Checked Items"/>
-
<asp:Button ID="ResetDataSource" runat="server" OnClick="ResetDataSource_Click" Text="Reset Data Source"/>
-
</div>
-
</form>
-
</body>
-
</html>
The C# code behind: -
using System;
-
using System.Collections.Generic;
-
using System.Linq;
-
using System.Web;
-
using System.Web.UI;
-
using System.Web.UI.WebControls;
-
-
namespace WebApplication1
-
{
-
public partial class WebForm1 : System.Web.UI.Page
-
{
-
/// <summary>
-
/// This property is used to get and set the source for the grid.
-
/// If there is not already a source stored in session, it creates one.
-
/// </summary>
-
private System.Data.DataTable Source
-
{
-
get
-
{
-
source = (System.Data.DataTable)Session["source"];
-
if (source == null)
-
{
-
source = new System.Data.DataTable();
-
source.Columns.Add(new System.Data.DataColumn("ID", typeof(int)));
-
source.Columns.Add(new System.Data.DataColumn("Name"));
-
for (int i = 0; i < 10; i++)
-
{
-
System.Data.DataRow dr = source.NewRow();
-
dr["ID"] = i;
-
dr["Name"] = String.Format("{0}{1}", "Name ", i + 1);
-
source.Rows.Add(dr);
-
}
-
Session["source"] = source;
-
-
}
-
return source;
-
}
-
set
-
{
-
source = value;
-
Session["source"] = source;
-
}
-
}
-
private System.Data.DataTable source;
-
-
-
protected void Page_Load(object sender, EventArgs e)
-
{ }
-
-
protected void DeleteSelectedRecord_Click(object sender, EventArgs e)
-
{
-
foreach (ListItem checkBoxListItem in theCheckboxList.Items)
-
{
-
-
if (checkBoxListItem.Selected)
-
{
-
int itemID;//Retrieving the item's ID
-
int.TryParse(checkBoxListItem.Value, out itemID);
-
-
//This is where you would update the database based on the record changed
-
//I'm not connected to a database so I am simply updating the in memory DataTable
-
string selectFilter = String.Format("{0}{1}{2}", "ID='", itemID, "'");//Used to retrieve the item checked from the source (DataTable) for the grid
-
System.Data.DataRow[] rows = Source.Select(selectFilter);//The rows that match the ID selected...this should be just 1 row.
-
if (rows.Length > 0)
-
rows[0].Delete();//here you would go to the database and delete the record
-
}
-
}
-
Source = source;//Saving the source for next time
-
}
-
-
protected void ResetDataSource_Click(object sender, EventArgs e)
-
{
-
Source = null;
-
}
-
-
void Page_PreRender(object sender, EventArgs e)
-
{
-
//Getting the source for the CheckBoxList and binding the CheckBoxList to the source.
-
theCheckboxList.DataSource = Source;
-
theCheckboxList.DataTextField = "Name";
-
theCheckboxList.DataValueField = "ID";
-
theCheckboxList.DataBind();
-
}
-
}
-
}
-Frinny
Sign in to post your reply or Sign up for a free account.
Similar topics
by: apple |
last post by:
Hello, please help me
I create a set of custom controls with IPostBackDataHandler, and postback processing.
All worked correctly, only custom checkbox control postback value change only if I do...
|
by: Francois |
last post by:
Hi,
I am trying to implement a custom control that extends the standard
System.Web.UI.WebControls.CheckBox control. In the .Net class library
reference it is said that CheckBox Implements...
|
by: Jennyfer J Barco |
last post by:
Hello, I have a datagrid that brings some information from a query. I need
to have a checkbox in each row so the user can select the rows he wants to
reprint. Is it possible to have a checkbox...
|
by: Graham |
last post by:
Is there a known bug with the CheckBox control?
I have subclassed the control and I am trying to add an onclick attribute in
the code behind. I've tried putting the Attributes.Add in the Page_Load,...
|
by: Steven |
last post by:
I am writing VB.NET, Can I add the checkbox control to a particular column
on the datagrid?
Thanks!
|
by: JP |
last post by:
I have images within a datalist control. Below is a checkbox control that
contains the SQL ID of the image blob.
When the page is post back I want to iterate though checkbox collection to
get...
|
by: schaefty |
last post by:
I recently posted this on the incorrect forum, and so I would like to
ask the question here. I did get some good ideas on the other group,
but I have not yet come up with a solution for me. I am...
|
by: mani.shanku |
last post by:
hi friendsplz..help me its urgent.....
im making a jobportal site..when a person go for search the results
should desplay....
like the naukri.com desplays..and when a person click on the checkbox...
|
by: bre1603 |
last post by:
I have a continuous form in Access 2007 called “Leadership Contact List.” It has a checkbox control for each record (bound to a field in the underlying table) that is used to email or create mailing...
|
by: Adewunmi Agbato |
last post by:
I just developing my web design skills.
I have a Datagrid with 2 textbox template columnsand two checkbox template columns. I have two other Textbox controls and two CheckBox controls. I have an...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |