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

}

Wednesday, October 28, 2009

RadWindow set size and more behaviors from code behind

rw.Width = Unit.Pixel(800);
rw.Height = Unit.Pixel(600);
rw.Behaviors = WindowBehaviors.Move & WindowBehaviors.Maximize & WindowBehaviors.Close;

SQL Server Reporting Services » how to add brackets around a value

question:

1. add brackets around a value

2. display or hide a string depending on a value. e.g. show "IDExists" in a textbox if Fields!ID != null, otherwise hide it

solution:

1. ="MemberID: (" & Fields!ID.Value &")"

2. =IIF (IsNothing(Fields!Id.Value), "","IdExist")

Friday, October 23, 2009

radwindow close window from code behind

http://www.telerik.com/help/aspnet/window/postbackandcloseonreload.html

Thursday, October 15, 2009

cater for sql apostrophe select condition in C#

Filter.Value = "LastName LIKE '" + tbLastNameFilter.Text.Trim().Replace("'", "''") + "%'";

Tuesday, October 13, 2009

How to remove duplicate rows from a table in SQL Server

http://support.microsoft.com/kb/139444

The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine

http://blog.crowe.co.nz/archive/2007/04/16/728.aspx

http://geekswithblogs.net/wpeck/archive/2009/04/30/quotthe-microsoft.jet.oledb.4.0-provider-is-not-registered-on-the-local-machine.quot.aspx


http://www.telerik.com/support/kb/aspnet-ajax/general/error-on-64-bit-windows-machines-the-microsoft-jet-oledb-4-0-provider-is-not-registered-on-the-local-machine.aspx

Turn Off “Saving Auto Recovery information” in Microsoft SQL Server Management Studio 2008

http://blog-mstechnology.blogspot.com/2009/06/turn-off-saving-auto-recovery.html

All Sample Connection String for All database using C#.Net and VB.Net

found this one useful

http://www.dotnetspider.com/resources/28823-All-Sample-Connection-String-for-All-database.aspx

Saturday, October 10, 2009

Saturday, October 03, 2009

datagridview checkbox column unable to fetch current row check status

need to use "datagridview1.EndEdit()" in "datagridview1_CellContentClick" event to finalize the editing of current row so that the changes made to the current row (in this case the change of check status) is submitted

Wednesday, September 30, 2009

oledbconnection problem "Unrecognized escape sequence....."

cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\ temp\\abc.mdb;User Id=admin;Password=;");
or
cn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\temp\ abc.mdb;User Id=admin;Password=;");

Sunday, September 27, 2009

Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine --------- dev error on vista x64 machine

this is because the driver is not x64. Solution: in project properties --> Build, select x86 in Platform Target

what's the status of a form after form1.show() and form1.hide() - Visual Studio 2008 Windows Form Application

in windows form application you can use Application.OpenForms collection to find the forms opened

Thursday, September 24, 2009

TSQL check if a view exists before create it

IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = 'vw_abc')
DROP VIEW [dbo].[vw_abc]

Thursday, August 06, 2009

Monday, August 03, 2009

C# ASP.NET use StringBuilder to export a txt file


StringBuilder strAAA = new StringBuilder();
foreach (DataRow drABC in datatableDEF.Rows)
{
strAAA.Append(drABC["xxxxx"]);
strAAA.Append(drABC[" "]);
strAAA.Append(drDEF["yyyyy"]);
strAAA.Append(drABC[" "]);
strAAA.Append(drGHI["zzzzzz"]);
strAAA.Append(drABC[" "]);
}

//end current line and start a new line
strAAA.AppendLine();
Response.AddHeader("content-disposition", "attachment;filename=ABC.txt"); Response.Charset = ""; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/vnd.text"; StringWriter stringWrite = new StringWriter(); HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); Response.Write(strAAA.ToString()); Response.End();

Thursday, July 30, 2009

sql get date within a datetime value

SELECT CONVERT(VARCHAR(10),GETDATE(),111)

--> returns 2009/07/30

SELECT CONVERT(VARCHAR(4),GETDATE(),111)
--> returns 2009

Friday, July 24, 2009

RadGrid allocate checkbox control within detailtable


the master table row must be expanded to open the detailtable before the value of the control can be accessed:



Monday, July 06, 2009

lost designer.aspx in asp.net web application

to fix it, right click on the aspx page in solution explorer and select Convert to Web Application"

RadGrid: rebind detailtable after command execution

e.Item.OwnerTableView.Rebind();

this only rebinds the detailtable, so the current expanding status will remain.

Friday, July 03, 2009

fetch the record primary key from MasterTable while using FormTemplate for insert and update

when you have a FormTemplate for insert and update in RadGrid.MasterTable, there is no commangArgument, therefore the record's primary key can not be passed on using commandargument.


This can be done by

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == "Update")
{
int RecordId= Convert.ToInt32(RadGrid1.MasterTableView.DataKeyValues[e.Item.ItemIndex]["RecordId"].ToString());
}
}

Thursday, July 02, 2009

RadGrid: rebind detailtable from external event

protected void ReBindExpandedDetailTable()
{
foreach (GridDataItem item in RadGrid1.Items)
{
string aaaValueString= item.GetDataKeyValue("aaa").ToString();

if (aaaValueString== )
{
if (item.Expanded == true)
{
GridTableView nestedView = ((GridDataItem)item).ChildItem.NestedTableViews[0];
nestedView.Rebind();
}
}
}
}

RadGrid: hide add new and refresh buttons from code behind

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridCommandItem)
{
GridCommandItem cmditm = (GridCommandItem)e.Item;
//to hide AddNewRecord button
cmditm.FindControl("InitInsertButton").Visible = false;//hide the text
cmditm.FindControl("AddNewRecordButton").Visible = false;//hide the image

//to hide Refresh button
cmditm.FindControl("RefreshButton").Visible = false;//hide the text
cmditm.FindControl("RebindGridButton").Visible = false;//hide the image


}
}

RadGrid: problem displaying bool value in formtemplate type edit form insert mode

I was able to update any records in the grid. However when I clicked on Add New Record, I received an error "specified cast is not valid" on the boolean field "IsActive".

see code below for my ASPX page content


The solution is:

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{


if (e.CommandName == RadGrid.InitInsertCommandName)
{
GridEditCommandColumn editColumn = (GridEditCommandColumn)rgQualificationList.MasterTableView.GetColumn("EditCommandColumn");
editColumn.Visible = false;

e.Canceled = true;
//Prepare an IDictionary with the predefined values
System.Collections.Specialized.ListDictionary newValues = new System.Collections.Specialized.ListDictionary();

//set initial checked state for the checkbox on init insert
newValues["IsActive"] = false;

//Insert the item and rebind
e.Item.OwnerTableView.InsertItem(newValues);
}

Wednesday, July 01, 2009

Display RadGrid row details in AjaxToolkit ModalPopupExtender

found this code library useful
http://www.telerik.com/community/code-library/aspnet-ajax/grid/display-radgrid-row-details-in-ajaxtoolkit-modalpopupextender.aspx

Thursday, June 18, 2009

show or hide nested table views RadGrid SP1 Q1 2009

protected void ShowOrHideNestedTableView()
{
foreach (GridDataItem CS in rgABC.Items)
{

if (CS.OwnerTableView.Name == "AAA")
{
if (cb123.Checked)
{
CS.Parent.Visible = true;
CS.Visible = true;
}
else
{
CS.Parent.Visible = false;
CS.Visible = false;
}
}

}
}

protected void rgScheduleList_PreRender(object sender, EventArgs e)
{
ShowOrHideNestedTableView();
}

Wednesday, June 17, 2009

aspx c# open new window in button click event when the button is placed inside an ajax update panel

val1 is an integer
val2 is a boolean

System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("window.open(abc.aspx?val1=" + val1Value.ToString() + "');");
ScriptManager.RegisterClientScriptBlock(this.upd1, this.upd1.GetType(), "abc", sb.ToString(), true);

aspx passing on multiple parameter values in URL

val1 is an integer
val2 is a boolean


in page 1:

aspx:

c#:
RadAjaxManager.GetCurrent(Page).ResponseScripts.Add("xxx('" + val1+ "',true);");

in page 2
c#
if (!string.IsNullOrEmpty(Request["val2"]))
{
if (bool.Parse(Request["val2"]))
----logic here---------
}


if (!string.IsNullOrEmpty(Request["val1"]))
{
if (int.Parse(Request["val1"])>0)
----logic here---------
}

Thursday, June 04, 2009

COALESCE

use COALESCE to manage a nullable db value, reference:
http://msdn.microsoft.com/en-us/library/ms190349.aspx

Monday, May 25, 2009

Error: Could not load file or assembly 'Telerik.Web.UI, Version=2009.1.402

Error: Could not load file or assembly 'Telerik.Web.UI, Version=2009.1.402.X, Culture=neutral, PublicKeyToken=XXXX' or one of its dependencies

Found some useful sources here:

This is the one helped me to solve my problem

Another one here

one more

Another one here Here

Friday, May 22, 2009

making radgrid filters case insensitive

GroupingSettings-CaseSensitive="false"

Friday, May 01, 2009

locate and hide BoundField in gridview asp.net c#



protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (Convert.ToString(DataBinder.Eval(e.Row.DataItem, "ABC")) == "Text To Be Found")
e.Row.Visible = false;
}
}

Friday, April 17, 2009

RadGrid hide column in export

RadGrid1.MasterTableView.Columns.FindByUniqueName("ABC").Visible = false;

sorting problem - RadGrid GridTemplateColumn

my code that has problem sorting template columns:



the instruction says "the SortExpression value should match the data field you want to sort on (typically the field a control in the template is bound to)". I made sure this rule is applied but the problem remained. Then I removed the HeaderTemplate components, instead I added value to HeaderText property in the GridTemplateColumn level. This solved the problem, not sure why though.....

the new code looks like:
...........
.......

Wednesday, April 15, 2009

RadGrid Insert UserControl does not close automatically after insert

use the following code below, make sure the CommandName on the Insert Button on the UserControl is named "PerformInsert"
protected void ABC_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) 
{  
if (e.CommandName == "PerformInsert")  
{  
//make sure the insert user control closes automatically after inserted
e.Item.OwnerTableView.IsItemInserted = false;  
}

Tuesday, April 14, 2009

ASP.NET How to deal with the message: error connecting to undo manager of source file "........"

* Delete the .designer.cs file
* convert the .aspx or ascx file into a webapplication by right clicking on it

Checked=' < % # DataBinder.Eval( Container, "DataItem.Active" ) % >'

C# Convert String to Guid

Guid ProductID = new Guid(String)

Friday, April 03, 2009

pre-populate value into RadGrid Insert



protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.InitInsertCommandName)
{
//enter the code here
}
}
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditFormInsertItem && RadGrid1.MasterTableView.IsItemInserted)
{
GridEditFormInsertItem insertItem = (GridEditFormInsertItem)e.Item;
(insertItem["abc"].Controls[0] as TextBox).Text = "hello world";
}
}

Monday, February 16, 2009

Visual Studio 2005 bug in ASP.NET applications

my web.config has multiple connection strings.
when I right click on a table adapter in a dataset in design view, select "configure...", the dataset configuration window pops up. Naturally you'd just make the changes that you want to the query and click on Finish. If this table adapter doesn't use the first connection string listed in the web.config, visual studio will automatically change the connection string to the first one listed in the web.config.

In order to fix the problem when you first open up the configuration window click on Previous to go back to the connection string selection view, RESELECT the connection string. If you happened to encounter this error until this stage right click on the empty area of the dataset design view and select View Code. Then delete the unused connection string.

Wednesday, February 04, 2009

ipconfig not working in cmd mode - Vista issue

when i tried to enter ipconfig in cmd mode it says: not valid command.

the solution is: right click on the cmd program and select "run as administrator".

why couldn't Vista run my programs as administrator when i logged in as administrator? this is stupid!