Thursday, July 02, 2009

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!

Tuesday, December 23, 2008

Compare mobile phone Cap Plans

found this tool very useful
http://www.mobchoice.com.au/compare-cap-plans-spreadsheet