Blog Archive
A directory of ASP.NET tutorials,ASP.NET Codebook,
Sunday, December 12, 2010
How do you modify style in the code behind file for divs in ASP.net?
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
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";
}
Wednesday, November 4, 2009
Send Email in ASP.Net 2.0 - Feed back Form
Introduction
We are using System.Web.Mail.SmtpMail
to send email in dotnet 1.1 which is obsolete in 2.0. The System.Net.Mail.SmtpClient
Class will provide us the same feature as that of its predecessor.
This article explains how to use System.Net.Mail
namespace to send emails.
Using the code
The HTML Design contains provision to enter sender�s name, email id and his comments. On click of the send email button the details will be sent to the specified email (Admin).
The Send mail functionality is similar to Dotnet 1.1 except for few changes
System.Net.Mail.SmtpClient
is used instead ofSystem.Web.Mail.SmtpMail
(obsolete in Dotnet 2.0).System.Net.MailMessage
Class is used instead ofSystem.Web.Mail.MailMessage
(obsolete in Dotnet 2.0)- The
System.Net.MailMessage
class collects From address as MailAddress object. - The
System.Net.MailMessage
class collects To, CC, Bcc addresses as MailAddressCollection. - MailMessage Body Format is replaced by IsBodyHtml
The Code is Self explanatory by itself.
protected void btnSendmail_Click(object sender, EventArgs e)
{
// System.Web.Mail.SmtpMail.SmtpServer is obsolete in 2.0
// System.Net.Mail.SmtpClient is the alternate class for this in 2.0
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
try
{
MailAddress fromAddress = new MailAddress(txtEmail.Text, txtName.Text);
// You can specify the host name or ipaddress of your server
// Default in IIS will be localhost
smtpClient.Host = "localhost";
//Default port will be 25
smtpClient.Port = 25;
//From address will be given as a MailAddress Object
message.From = fromAddress;
// To address collection of MailAddress
message.To.Add("admin1@yoursite.com");
message.Subject = "Feedback";
// CC and BCC optional
// MailAddressCollection class is used to send the email to various users
// You can specify Address as new MailAddress("admin1@yoursite.com")
message.CC.Add("admin1@yoursite.com");
message.CC.Add("admin2@yoursite.com");
// You can specify Address directly as string
message.Bcc.Add(new MailAddress("admin3@yoursite.com"));
message.Bcc.Add(new MailAddress("admin4@yoursite.com"));
//Body can be Html or text format
//Specify true if it is html message
message.IsBodyHtml = false;
// Message body content
message.Body = txtMessage.Text;
// Send SMTP mail
smtpClient.Send(message);
lblStatus.Text = "Email successfully sent.";
}
catch (Exception ex)
{
lblStatus.Text = "Send Email Failed." + ex.Message;
}
}
License
original source :http://www.codeproject.com/KB/aspnet/EmailApplication.aspxThanks to the author :Gowrisankar K Location: India
Monday, October 5, 2009
How to use a SqlTransaction SqlConnections in .NET? -
SqlTransaction transaction = cnnGlobal.BeginTransaction(IsolationLevel.Serializable);//cnnGlobal is connection
try
{
SqlCommand cmdMaster = new SqlCommand(sql, cnnGlobal);//sql is sql command
cmdMaster.Transaction = transaction;
cmdMaster.ExecuteNonQuery();
SqlCommand cmdDetails;
for (int i = 0; i <>
{
cmdDetails = new SqlCommand(sql, cnnGlobal);
cmdDetails.Transaction = transaction;
cmdDetails.ExecuteNonQuery();
}
transaction.Commit();
transaction = null;
cmdMaster.Dispose();
cmdDetails.Dispose();
}
catch
{
if (transaction != null)
{
transaction.Rollback();
transaction = null;
}
}
other example :
static void Main(string[] args)
{
string insertQuery =
@"INSERT TESTTABLE (COLUMN1, COLUMN2) " +
"VALUES(@ParamCol1, @ParamCol2)";
using (SqlConnection connection =
new SqlConnection(connectionString))
{
using (SqlCommand command =
connection.CreateCommand())
{
SqlTransaction transaction = null;
try
{
// BeginTransaction() Requires Open Connection
connection.Open();
transaction = connection.BeginTransaction();
// Assign Transaction to Command
command.Transaction = transaction;
for (int i = 0; i < 100; i++)
CommandExecNonQuery(command, insertQuery,
new SqlParameter[] {
new SqlParameter("@ParamCol1", i),
new SqlParameter("@ParamCol2", i.ToString()) });
transaction.Commit();
}
catch
{
transaction.Rollback();
throw;
}
finally
{
connection.Close();
}
}
}
}
Tuesday, September 29, 2009
iis showCannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later
I am a new .Net developer.
i was given an existing DB, and modified it for my department.
I intalled Visual Studio on my PC, and I think I have IIS going correctly (I can create a virtual server). But when I go to launch my homepage I get:
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
A name was started with an invalid character. Error processing resource 'http://localhost/Publishtest/Home.aspx'. Line 1, ...
<%@ Reference Page="~/Search.aspx" %>
-^
I see this error all over these forums but i haven't been able to figure it out yet. Is there a bad path somewhere? Any help is appreciated, I'm so new.
Thanks!
try to run
%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -i
or see
How to repair IIS mapping after you remove and reinstall IIS
http://support.microsoft.com/default.aspx?kbid=306005&product=aspnet
The solution is here
MORE INFORMATION
ASP.NET, run the Aspnet_regiis.exe utility:
- Click Start, and then click
Run. - In the Open text box, type cmd, and then press ENTER.
- At the command prompt, type
the following, and then press ENTER:"%windir%\Microsoft.NET\Framework\version\aspnet_regiis.exe" -iIn this path, version represents the version number of the .NET Framework that you
installed on your server. You must replace this placeholder with the actual
version number when you type the command.
Tuesday, July 7, 2009
numericupdown trouble do not show decimal value.
{
string value = numericUpDown1.Value.ToString();
int numOfDecimalPlaces = 0;
if (value.Contains("."))
{
string[] splitString = value.Split(new char[] { '.' });
numOfDecimalPlaces = splitString[1].Length;
}
numericUpDown1.DecimalPlaces = numOfDecimalPlaces;
}
ref : http://www.dreamincode.net/forums/showtopic81889.htm