середу, 23 грудня 2009 р.

not null -> true and null -> false


select
CASE
when ImageFile is NULL then 0
else 1
end as HasImage
from News

Bind to ItemIndex

Repeater:
<% #DataBinder.Eval(Container, "ItemIndex") %>
Gridview:
<% #DataBinder.Eval(Container, "RowIndex") %>

четвер, 29 жовтня 2009 р.

Footer always bottom



HTML:

<div id="container">
<div id="main">
<div id="header">
<h2>
header
</h2>
</div>
<div id="content">
<h2>
content content content content<br />
content content content content<br />
content content content content<br />
content content content content<br />
</h2>
</div>
</div>
</div>
<div id="footer">
<h2>
footer
</h2>
</div>

CSS:

*{padding:0; margin:0;}
html {height: 100%;}
body {height: 100%;}
#container {min-height: 100%;}
* html #container {height: 100%;}
#header {height: 110px;}
#footer {height: 90px;position: relative;margin-top:-90px;}
#main {min-height: 100%;}
* html #main{height: 100%;}
#content {padding-bottom: 90px;}

#header{background:red;}
#container {background:#aaa;}
#content{background:green;}
#footer{background:blue;}

Body min-height 100%


html
{
height:100%;
}
body
{
margin:0px;
min-height:100%;
height:100%;
height:auto !important;
}

Div min-height


#content
{
min-height:400px;
height:auto !important;
height:400px;
}

середу, 29 липня 2009 р.

GridView + autopostback CheckBox


в темплейтах колонок прописуємо:

asp:CheckBox ID="chb1" AutoPostBack="true"
key='<%# Eval("ID") %>'
runat="server"
OnCheckedChanged="chb1_CheckedChanged"

а в коді:
protected void chb1_CheckedChanged(object sender, EventArgs e)
{
CheckBox chb = (CheckBox)sender;
string id = chb.Attributes["key"];
...
}

вівторок, 14 липня 2009 р.

Validation of ViewState Mac failed

Від цієй проблеми допоможуть наступні параметри розділу pages в web.config:

validateRequest="false"
enableEventValidation="false"
viewStateEncryptionMode ="Never"

четвер, 18 червня 2009 р.

asp.net calendar: disable past months


protected void Calendar1_VisibleMonthChanged(object sender, MonthChangedEventArgs e)
{
if (e.NewDate < DateTime.Today)
Calendar1.VisibleDate = DateTime.Today;
}

четвер, 4 червня 2009 р.

Ajax CascadingDropDown: method error 500

Якщо Вы заюзали CascadingDropDown і отримали method error 500,
то потрібно лише додати атрибут
[System.Web.Script.Services.ScriptService()]
до класу вашого сервіса.

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService()]
public class ClientsService : System.Web.Services.WebService
{...}

вівторок, 2 червня 2009 р.

MSSQL split function


CREATE FUNCTION [dbo].[Split](@text nvarchar(max))
RETURNS @Strings TABLE
(
value nvarchar(max)
)
AS
BEGIN
DECLARE @index int
DECLARE @delimiter char(1)

SET @index = -1
SET @delimiter = ','

WHILE (LEN(@text) > 0)
BEGIN
SET @index = CHARINDEX(@delimiter , @text)
IF (@index = 0) AND (LEN(@text) > 0)
BEGIN
INSERT INTO @Strings VALUES (@text)
BREAK
END
IF (@index > 1)
BEGIN
INSERT INTO @Strings VALUES (LEFT(@text, @index - 1))
SET @text = RIGHT(@text, (LEN(@text) - @index))
END
ELSE
SET @text = RIGHT(@text, (LEN(@text) - @index))
END
RETURN
END

четвер, 28 травня 2009 р.

Простір імен System.Transactions

транзакції з попереднього поста добре підходять для використання на рівні DAL коли в нас є доступ до об'єкта Connection.
коли ж потрібні транзакції на рівні BLL(де про Connection не повинно йти і мови)
можна використовувати класи з нового в .Net 2.0 простіру імен System.Transactions.

using (TransactionScope ts = new TransactionScope())
{
//тут виконуєпо потрібні операції

...

ts.Complete();
}


P.S. і не забудьте запустити службу Distributed Transaction Coordinator. без неї не працює.

Приклад ADO.NET транзакції


using (SqlConnection con = new SqlConnection(...))
{
con.Open();
SqlTransaction t = con.BeginTransaction();
using (SqlCommand c = new SqlCommand())
{
//тут виконуєпо потрібні операції
try
{
c.Connection = con;
c.Transaction = t;
c.CommandText = "text1";
c.ExecuteNonQuery();
c.CommandText = "text2";
c.ExecuteNonQuery();

//якщо все ОК - коммітимо
t.Commit();
}
catch (Exception exc)
{
//якщо трабл - робимо віткат
t.Rollback();
}
}
}

понеділок, 18 травня 2009 р.

JQuery + asp.net UpdatePanel

Щоб JQuery код працював і після оновлення UpdatePanel потрібно виконати його і після апдейта панелі.
наприклад:

$(function(){
Init();
Sys.Application.add_load(Init);
});

function Init(){
$('.tooltip-link').tooltip();
}

середу, 29 квітня 2009 р.

Наткнувся на прикольний аплоад













Кульний аплоад jQuery+Flash з прогресбаром.

пʼятницю, 24 квітня 2009 р.

Ура-а-а!!!

ха-ха! в мене тепер теж є блог!!! :)