Monday, August 23, 2010

multiple delete in gridview

USE [DB]
GO
/****** Object: UserDefinedFunction [dbo].[Split] Script Date: 08/23/2010 12:45:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create FUNCTION [dbo].[Split]
(
@RowData NVARCHAR(MAX),
@Delimeter NVARCHAR(MAX)
)
RETURNS @RtnValue TABLE
(
ID INT IDENTITY(1,1),
Data NVARCHAR(MAX)
)
AS
BEGIN
DECLARE @Iterator INT
SET @Iterator = 1

DECLARE @FoundIndex INT
SET @FoundIndex = CHARINDEX(@Delimeter,@RowData)

WHILE (@FoundIndex>0)
BEGIN
INSERT INTO @RtnValue (data)
SELECT
Data = LTRIM(RTRIM(SUBSTRING(@RowData, 1, @FoundIndex - 1)))

SET @RowData = SUBSTRING(@RowData,
@FoundIndex + DATALENGTH(@Delimeter) / 2,
LEN(@RowData))

SET @Iterator = @Iterator + 1
SET @FoundIndex = CHARINDEX(@Delimeter, @RowData)
END

INSERT INTO @RtnValue (Data)
SELECT Data = LTRIM(RTRIM(@RowData))

RETURN
END
GO
-------------------------------
USE [DB]
GO
/****** Object: StoredProcedure [dbo].[SP_UPDATE_JobPosted_Approved] Script Date: 08/23/2010 14:10:44 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[SP_UPDATE_JobPosted_Approved]
(
@IDs NVARCHAR(MAX)
)
AS

DECLARE @Data nvarchar(20)

DECLARE db_cursor CURSOR FOR
SELECT Data
FROM Split(@IDs, ',')

OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @Data

WHILE @@FETCH_STATUS = 0
BEGIN
UPDATE tblJobPosted
SET Approved = '1'
WHERE JobPostedID = CAST(@Data AS INT)

FETCH NEXT FROM db_cursor INTO @Data
END

CLOSE db_cursor
DEALLOCATE db_cursor


RETURN
------------------------------
#region updateFeedback
private void updateFeedback(string isDelete)
{
try
{
string _IDs = "";
foreach (GridViewRow row in dvMyJobs.Rows)
{
CheckBox chk = (CheckBox)row.FindControl("chkSelect");

if (chk.Checked)
_IDs += ((Label)row.FindControl("lblJobPostedID")).Text + ",";
}

if (_IDs.Contains(","))
{
_IDs = _IDs.Remove(_IDs.LastIndexOf(','), 1);


ProcessUpdateJobPostApprovalByAllID _updateJobPostApprovalByAllID = new ProcessUpdateJobPostApprovalByAllID();
_updateJobPostApprovalByAllID.IDs = _IDs;
_updateJobPostApprovalByAllID.invoke();
// bindData();

}
}
catch (Exception ex)
{ }
}
#endregion
protected void btnApproved_Click(object sender, EventArgs e)
{
updateFeedback("1");
}

No comments:

Counter