Sunday, December 12, 2010

How do you modify style in the code behind file for divs in ASP.net?

It's an HtmlGenericControl so not sure what the recommended way to do this is, so you could also do:

testSpace.Attributes.Add("style", "text-align: center;");

or

testSpace.Attributes.Add("class", "centerIt");

or

testSpace.Attributes["style"] = "text-align: center;";

or

testSpace.Attributes["class"] = "centerIt";

for more details read

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");
}

Sunday, August 22, 2010

Datagridview and datalist DataBound

Data Gridview formating :

public int i = 0;

protected void gvjobsCategory_RowDataBound(object sender, GridViewRowEventArgs e)

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

if (i % 2 == 0)

{

e.Row.CssClass = "job_a"; ;

}

else { e.Row.CssClass = "job_b"; ;}

i++;

}

productsGridView_RowDataBound Event Handler (C#)

void productsGridView_RowDataBound(object sender,

GridViewRowEventArgs e)

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

// determine the value of the UnitsInStock field

int unitsInStock =

Convert.ToInt32(DataBinder.Eval(e.Row.DataItem,

"UnitsInStock"));

if (unitsInStock == 0)

// color the background of the row yellow

e.Row.BackColor = Color.Yellow;

}

}

Data List formating :

protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)

{

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)

{

// Retrieve the Label control in the current DataListItem.

Label PriceLabel = (Label)e.Item.FindControl("Label1");

// Format the value as currency and redisplay it in the DataList.

PriceLabel.CssClass = "job_a";

}

Counter