What do you do when you have
AllowPaging="False" AllowSorting="False" AutoGenerateColumns="True" Width="800px" ShowHeader="true"
And it wraps all your data?
you add:
OnRowDataBound="GridView_RowDataBound"
and then:
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].Attributes.Add("style", "white-space: nowrap;");
}
}
SQL, C#, VB, .net, asp, JavaScript, you name it. Code samples, Error messages and stuff like that. Please add coments if you think I said something stupid :D or if you have a better idea ... or anything at all ...
Thursday, April 1, 2010
Tuesday, March 2, 2010
Enum to DataTable
I had a lot of ENUM-s and needed to make DataTable - s with the same structure for pretty much all of them.
I came up with this:
private static DataTable CreateDataTable < TheSQLtable > ()
{
Type t = typeof(TheSQLtable);
if (!t.IsEnum)
{
throw new InvalidOperationException("Type is not Enum");
}
DataTable dt = new DataTable();
dt.TableName = t.Name;
DataColumn dc;
string[] names = Enum.GetNames(t);
foreach (string name in names)
{
dc = new DataColumn();
dc.DataType = System.Type.GetType("System.String");
dc.ColumnName = name;
dc.Unique = false;
dt.Columns.Add(dc);
}
return dt;
}
(with a little help from stackoverflow)
I came up with this:
private static DataTable CreateDataTable < TheSQLtable > ()
{
Type t = typeof(TheSQLtable);
if (!t.IsEnum)
{
throw new InvalidOperationException("Type is not Enum");
}
DataTable dt = new DataTable();
dt.TableName = t.Name;
DataColumn dc;
string[] names = Enum.GetNames(t);
foreach (string name in names)
{
dc = new DataColumn();
dc.DataType = System.Type.GetType("System.String");
dc.ColumnName = name;
dc.Unique = false;
dt.Columns.Add(dc);
}
return dt;
}
(with a little help from stackoverflow)
Wednesday, February 24, 2010
How to check in C# if a DataRow is Empty. (nothing in any column)
I was hoping i find something like dr.isEmpty(), but there's nothing "this nice". So you do something plain like:
bool AreAllColumnsEmpty(DataRow dr)
{
if (dr == null)
{
return true;
}
else
{
foreach(var value in dr.ItemArray)
{
if (value != null)
{
if (value.ToString() != "")
{
return false;
}
}
}
return true;
}
}
bool AreAllColumnsEmpty(DataRow dr)
{
if (dr == null)
{
return true;
}
else
{
foreach(var value in dr.ItemArray)
{
if (value != null)
{
if (value.ToString() != "")
{
return false;
}
}
}
return true;
}
}
Thursday, November 5, 2009
Monday, October 12, 2009
SQL split
found this on the net
i like this very much
CREATE TABLE #t (UserName VARCHAR(50))
DECLARE @sql VARCHAR(MAX)
SELECT @sql = 'INSERT INTO #t SELECT ''' + REPLACE(@UserList, ',', ''' UNION SELECT ''') + ''''
PRINT (@sql)
EXEC (@sql)
SELECT * FROM #t
IF OBJECT_ID('tempdb..#t') IS NOT NULL BEGIN DROP TABLE #t END
you can feedback also :)
i like this very much
CREATE TABLE #t (UserName VARCHAR(50))
DECLARE @sql VARCHAR(MAX)
SELECT @sql = 'INSERT INTO #t SELECT ''' + REPLACE(@UserList, ',', ''' UNION SELECT ''') + ''''
PRINT (@sql)
EXEC (@sql)
SELECT * FROM #t
IF OBJECT_ID('tempdb..#t') IS NOT NULL BEGIN DROP TABLE #t END
you can feedback also :)
Friday, October 2, 2009
Disable browser's back button ?
you can disable the back button, they say.
didn't test the code yet, will be back with feedback
< script type="text/javascript">
function noBack(){window.history.forward()}
noBack();
window.onload=noBack;
window.onpageshow=function(evt){if(evt.persisted)noBack()}
window.onunload=function(){void(0)}
< / script>
you can feedback also :)
didn't test the code yet, will be back with feedback
< script type="text/javascript">
function noBack(){window.history.forward()}
noBack();
window.onload=noBack;
window.onpageshow=function(evt){if(evt.persisted)noBack()}
window.onunload=function(){void(0)}
< / script>
you can feedback also :)
Tuesday, June 30, 2009
Session state can only be used when enablesessionstate is set to true
I had a JavaScript function, that called a WebService, and I had this "Session state can only be used when enablesessionstate is set to true ..." error over and over again.
Everything was all right, in the web.config and in the "< % @ Page " too.
It was still giving me the error.
I made it work doing this:
start -- control panel -- administrative tools -- services -- asp.net state server
by default it is stopped. i started it.
that's it.
Everything was all right, in the web.config and in the "< % @ Page " too.
It was still giving me the error.
I made it work doing this:
start -- control panel -- administrative tools -- services -- asp.net state server
by default it is stopped. i started it.
that's it.
Subscribe to:
Posts (Atom)