Tuesday, June 29, 2010

find column value when updating RadGrid item using EditItemTemplate

if (e.CommandName == RadGrid.UpdateCommandName)
{
GridEditableItem editable = e.Item as GridEditableItem;
int TheId= Convert.ToInt32(editable.OwnerTableView.DataKeyValues[editable.ItemIndex]["TheId"].ToString());

Wednesday, May 05, 2010

asp.net logout user

FormsAuthentication.Signout();

Response.Resirect([loginURL]);

Friday, April 23, 2010

T-SQL loop through all rows in a table to add an incremental value

DECLARE @tempTable table(Id INT NOT NULL PRIMARY KEY)
DECLARE @counter INT
INSERT INTO @tempTable SELECT UserId from TestTable
SET @counter = 1
WHILE (@counter < (SELECT COUNT(UserId) FROM @tempTable)+1)
BEGIN
UPDATE TestTable SET TestColumn = '' WHERE Id = (
SELECT a.Id FROM
(SELECT Id, Row_Number() OVER(ORDER BY UserId) AS 'RN' from TestTable) as a
where a.RN = @counter
)
SET @counter = @counter + 1
END

Wednesday, April 21, 2010

RadGrid wont expand after updated to Q1 2010

This is because the detail table is set to "visible=false" during the update process. Not all RadGrid controls in the application get this symptom, not sure why this happens. All you need to do is to change the setting to "visible = true"

Tuesday, April 20, 2010

T-SQL division

I came cross this this issue of failing to do a division with 2 integer values. Stupid enough......

so In order for the division to work i used CAST(value TO FLOAT)

Monday, April 19, 2010

Setup Radwindow on button in code behind

int tempId= 168;
RadWindow rw = rwmTEMP.Windows[0];
rw.Width = System.Web.UI.WebControls.Unit.Pixel(1000);
rw.Height = System.Web.UI.WebControls.Unit.Pixel(1000);
rw.Behaviors = WindowBehaviors.Move | WindowBehaviors.Close | WindowBehaviors.Maximize | WindowBehaviors.Resize;
rw.OpenerElementID = btnOpenWindow.ClientID;

rw.NavigateUrl = "~/xxxxx/abccc.aspx?TempId=" + tempId.ToString();

Thursday, April 01, 2010

add new line in ajaxToolkit:ConfirmButtonExtender's ConfirmText

use the combination of &,#,10, and ; to create a new line

Friday, February 26, 2010

mssql reset table identity

the following script resets the table identity seeding to 99, the next record will have identity of 100

DBCC CHECKIDENT ("[table name]", RESEED, 99);
GO

Friday, February 12, 2010

Monday, February 08, 2010

RadGrid Export Button does not work

if the buttons are located within a RadAjaxPanel or RadUpdatePanel the button must be registered for postback event. This can be done in aspx or code behind:
C#:
ScriptManager.GetCurrent(Page).RegisterPostBackControl(ExportCSVButton);
ASPX:

Thursday, February 04, 2010

sql how to replace the time value in datetime column

update Table1
SET StartDateTime = CONVERT(datetime,
CONVERT(VARCHAR(10),StartDateTime , 101)
+' '+CONVERT(VARCHAR,datepart(HH,NewStartTime))
+':'+CONVERT(VARCHAR,datepart(MI,NewStartTime))
+':'+CONVERT(VARCHAR,datepart(SS,NewStartTime))
+':'+CONVERT(VARCHAR,datepart(Ms,NewStartTime))
)

Wednesday, February 03, 2010

replace time in datetime value c#

I have 2 datetime values: StartDateTime ('11/01/2010 00:00:00') and NewStartTime('12/02/2010 09:30:00 AM'). I want to replace the time value in StartDateTime with the time value in NewStartTime. In order to achieve so I go:
DateTime NewStartDateTime = new DateTime(StartDateTime.Year, StartDateTime.Month, StartDateTime.Day, NewStartTime.Hour, NewStartTime.Minute, NewStartTime.Second);

System.Web.HttpException: Request is not available in this context

this is caused by using "Request["xxx"]"
a quick fix is to use "HttpContext.Current.Request" instead

Wednesday, January 13, 2010

sql replace substring with value from associated table

Update TableA
set ColumnA1 = (select a.ColumnA from
(
"SELECT" REPLACE("t.ColumnA1, t.ColumnA2", (select "ColumnB1 from TableA where ColumnB2= t.ColumnA2))
FROM TableA t
) a
where TableA.ColumnA2 = a.ColumnA2)
GO

Wednesday, December 16, 2009

RadMenu hide menu item from server side

RadMenu1.FindItemByText("RadMenuItem1").Visible = false;

Tuesday, December 15, 2009

determine whether radscheduler is in edit mode or insert mode

Edit Mode:
"if"(!RadScheduler1.StartEditingInAdvancedForm)

Insert Mode:
"if"(!RadScheduler1.StartInsertingInAdvancedForm)

Thursday, December 10, 2009

asp.net export to txt file receive error in IE when hosted in IIS6

code:

"Response".Clear();
"Response".AddHeader("content-disposition", "attachment;filename=" + FileName + ".txt");
"Response".Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
"Response".ContentType = "application/vnd.text";
"StringWriter" stringWrite = new StringWriter();
"HtmlTextWriter" htmlWrite = new HtmlTextWriter(stringWrite);
"Response".Write(strTXTFileBuilder.ToString());
"Response".End();

Error:
Internet Explorer cannot download file from .
Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later.

My Solution:
Take out the line "
"Response".Cache.SetCacheability(HttpCacheability.NoCache);"

Wednesday, December 09, 2009

sql check existance before insert

'if' not 'exists' (select .... from .... where ....)
Begin
'Insert' Into ....... (..., ..., ...) values (..., ..., ...,)
END

Thursday, December 03, 2009

rebind parent page control on radwindow close

in the Parent page add into the radwinow aspx code:

sas"<"telerik:radwindow id="rwpopup111" title="popup111" runat="server" behaviors="Close" onclientclose="OnClientClose" navigateurl="popup111.aspx">

also add javascript:

function OnClientClose(oWnd)
{
//place your code to execute, see below for my examples, in this example I rebind a grid:
var hf111 = document.getElementById("");


var masterTable1 = $find("").get_masterTableView();
masterTable1.rebind();

var masterTable = $find("").get_masterTableView();
masterTable.rebind();
//after radwindow close you may lose title of the parent page, if that is the case reset it here:
document.title="abc";

}