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