28.12.08

Make Temporary table for Shopping cart:

How to make Temporary table for shopping cart:

1.)public String GetShoppingCartId()
{

// Obtain current HttpContext of ASP+ Request
System.Web.HttpContext context = System.Web.HttpContext.Current;

// If the user is authenticated, use their customerId as a permanent shopping cart id
if (context.User.Identity.Name != "")
{
return context.User.Identity.Name.ToString();
}

// If user is not authenticated, either fetch (or issue) a new temporary cartID
if (context.Request.Cookies["ASPNETCommerce_CartID"] != null)
{
return context.Request.Cookies["ASPNETCommerce_CartID"].Value;
}
else
{
// Generate a new random GUID using System.Guid Class
Guid tempCartId = Guid.NewGuid();

// Send tempCartId back to client as a cookie
context.Response.Cookies["ASPNETCommerce_CartID"].Value = tempCartId.ToString();

// Return tempCartId
return tempCartId.ToString();
}
}


2.) public void BLL_AddItem( Products objBol)
{
ShoppingCart cart = new ShoppingCart();
String cartID = cart.GetShoppingCartId();
Int16 lintCartItemID = 0;

//Declare a datatable to be used as shopping cart
DataTable objDT;
DataRow objDR;

if (System.Web.HttpContext.Current.Session["SessionCart"] == null)
{
//Data table to be used as cart
objDT = new DataTable("Cart");

//Declaring Primary Key For Table
objDT.Columns.Add("ID", System.Type.GetType("System.Int32"));
DataColumn[] ldataColPK = new DataColumn[2];
ldataColPK[0] = objDT.Columns["ID"];
ldataColPK[0].AutoIncrement = true;
ldataColPK[0].AutoIncrementSeed = 1;
objDT.PrimaryKey = ldataColPK;

//Adding columns to datatable
objDT.Columns.Add("CartID", System.Type.GetType("System.String"));
objDT.Columns.Add("ProductID", System.Type.GetType("System.Int32"));
objDT.Columns.Add("Products_Name", System.Type.GetType("System.String"));
objDT.Columns.Add("Model", System.Type.GetType("System.String"));
objDT.Columns.Add("Size", System.Type.GetType("System.String"));
objDT.Columns.Add("Colour", System.Type.GetType("System.String"));
objDT.Columns.Add("ImageUrl", System.Type.GetType("System.String"));
objDT.Columns.Add("Price", System.Type.GetType("System.Double"));
objDT.Columns.Add("Description", System.Type.GetType("System.String"));
objDT.Columns.Add("Quantity", System.Type.GetType("System.Int32"));
objDT.Columns.Add("Stock", System.Type.GetType("System.Int32"));
objDT.Columns.Add("Amount", System.Type.GetType("System.Double"));
objDT.Columns["Amount"].Expression = "Price * Quantity";
}
else
{
objDT = (DataTable)System.Web.HttpContext.Current.Session["SessionCart"];
}

objDR = objDT.NewRow();
objDR["CartID"] = cartID;
objDR["ProductID"] = objBol.ProductsID;
objDR["Products_Name"] = objBol.Products_Name;
objDR["Model"] = objBol.Model;
objDR["Size"] = objBol.attributes_values_name;
objDR["Colour"] = objBol.Colour_name;
objDR["ImageUrl"] = objBol.Icon_image;
objDR["Price"] = objBol.Price;
objDR["Description"] = objBol.Products_Description;
objDR["Quantity"] = objBol.Quantity;
objDR["Stock"] = objBol.Stock;
System.Web.HttpContext.Current.Session["CartItemID"] = objDR["ID"].ToString();
lintCartItemID = Convert.ToInt16(objDR["ID"]);
objDT.Rows.Add(objDR);

//Add the datatable in a session variable
System.Web.HttpContext.Current.Session["SessionCart"] = objDT;

}

Asp.net and Telerik

Asp.net and Telerik --My Points;

1.)How to make radgrid column visible false.

ViewState["intParentID"] = Convert.ToInt32(Request.QueryString["id"]);

if (ViewState["intParentID"].ToString () != "0")
{
RadgridDisplayCategories.MasterTableView.Columns[1].Visible= false;

}

**********************
2.) Radgrid edit command categoryid value pick up:
int Category_id = Convert.ToInt32(RadgridDisplayCategories.MasterTableView.DataKeyValues[e.Item.ItemIndex]["CategoryID"]);
Response.Redirect("EditCategories.aspx?cid=" + Category_id);

**********************

3.)Javascript alert on page:and delete command of telerik radgrid

int Category_id = Convert.ToInt32(RadgridDisplayCategories.MasterTableView.DataKeyValues[e.Item.ItemIndex]["CategoryID"]);
DataSet objDsCheck = objBll.BLL_DisplayCategories(Category_id);
if (objDsCheck.Tables[0].Rows.Count > 0)
{



}
string strIconpath = "~/CategoriesImages/Icon/" + Category_id+".jpg";
string strmediumpath = "~/CategoriesImages/Medium/" + Category_id + ".jpg";
string strlargepath = "~/CategoriesImages/Large/" + Category_id + ".jpg";
System.IO.File.Delete(Server.MapPath(strIconpath));
System.IO.File.Delete(Server.MapPath(strmediumpath));
System.IO.File.Delete(Server.MapPath(strlargepath));

objBll.BLL_DeleteCategory(Category_id);
**********************

4.)Radgrid hyperlink column querystring pass:

UniqueName="column1">


5.) User control and telerik Controls Register on html page and use:
1.)Radgrid:<%@ Register Assembly="RadGrid.Net2" Namespace="Telerik.WebControls" TagPrefix="radG" %>
2.)<%@ Register Src="../UserControls/HeaderBar.ascx" TagName="HeaderBar" TagPrefix="uc1" %>
3.)<%@ Register Src="../UserControls/Footer.ascx" TagName="Footer" TagPrefix="uc2" %>
4.) <%@ Register Assembly="Fluent.MultiLineTextBoxValidator" Namespace="Fluent" TagPrefix="cc1" %>
5.) <%@ Register Assembly="RadComboBox.Net2" Namespace="Telerik.WebControls" TagPrefix="radC" %>
6.) <%@ Register Assembly="RadAjax.Net2" Namespace="Telerik.WebControls" TagPrefix="radA" %>
7.) <%@ Register TagPrefix="radcln" Namespace="Telerik.WebControls" Assembly="RadCalendar.Net2" %>
8.) <%@ Register TagPrefix="telerik" Namespace="Telerik.WebControls" Assembly="RadEditor.Net2" %>
******************************
a.)





b.)
c.) EnableClientSideRestriction="True" MaxLength="400" ShowCharacterCount="false"
ShowJavascriptAlert="False">


d.)
EnableLoadOnDemand="True" HighlightTemplatedItems="True" DropDownWidth="300px"
ItemRequestTimeout="500" SkinsPath="~/RadControls/skins" RadControlsDir="~/RadControls/skins/"
Skin="WindowsXP"
OnSelectedIndexChanged="RadComboBox2_SelectedIndexChanged" AutoPostBack="True">






Size

Colour

Quantity




<%# DataBinder.Eval(Container.DataItem, "attributes_values_name")%>

<%# DataBinder.Eval(Container.DataItem, "Colour_name") %>

<%# DataBinder.Eval(Container.DataItem, "Quantity")%>


private void DisplaySize()
{
RadComboBox2.DataSource = objBll.BLL_DspProductsSize(Convert.ToInt32(ViewState["ProductsID"]));
RadComboBox2.DataTextField = "attributes_values_name";
RadComboBox2.DataValueField = "Quantity";
RadComboBox2.DataBind();
lblquantity.Text = RadComboBox2.SelectedValue.ToString();
}

e.)


f.) runat="server" MaxDate="3000-12-31" MinDate="2008-03-01" SkinsPath="" Skin=""
EnableTyping="False">



g.) Height="350px" Width ="500px" RadControlsDir="~/RadControls/"
SkinsPath="~/RadControls/Editor/" Skin ="WebBlue"
ToolsFile="~/RadControls/Editor/ToolsFile.xml"
ShowSubmitCancelButtons="False" EnableTab="False"
UseClassicDialogs="True" >

************************************
6.)Validators:
1.)Use javascript on fileupload control:


2.) Category Name:

Display="Dynamic" ErrorMessage="Enter Name" SetFocusOnError="True" ValidationGroup="Save">


3.) Description:

runat="server">

EnableClientSideRestriction="True" MaxLength="400" ShowCharacterCount="false"
ShowJavascriptAlert="False">


******************
7.)Use trim when u use textbox:

objBol.Category_code = textcatcod.Text.Trim();


******************
8.)
a.)Retrieve values from dataset:

DataSet objds;
objds = objBll.BLL_EditCategories(Convert.ToInt32(ViewState["intCatID"]));
textcatname.Text = objds.Tables[0].Rows[0]["Category_name"].ToString();
textcatcod.Text = objds.Tables[0].Rows[0]["Category_code"].ToString();

b.)Retrieve values from List:
List objlist = new List();
objlist = objBll.BLL_DspProductsBYID(Convert.ToInt32(ViewState["ProductsID"]));
textName.Text = objlist[0].Products_Name.ToString();
textModel.Text = objlist[0].Model.ToString();
DrpProductType .SelectedValue = objlist[0].Products_Type.ToString ();



9.)when mastertableview and detailtables use simultaneously of radgrid insert and update record:

a.)Insert: protected void RadGrid1_InsertCommand(object source, Telerik.WebControls.GridCommandEventArgs e)
{ GridEditableItem edititem = e.Item as GridEditableItem;
if ("Attributes_values".Equals(e.Item.OwnerTableView.Name))
{ GridDataItem parentItem = e.Item.OwnerTableView.ParentItem as GridDataItem;
Int32 attributes_id =Convert.ToInt32(parentItem.OwnerTableView.DataKeyValues[parentItem.ItemIndex]["attributes_id"]);
TextBox txtname = edititem.FindControl("TextBox2") as TextBox;
objBol.attributes_values_name = txtname.Text.Trim();
objBol.attributes_id = attributes_id;
objBll.Bll_InsUpdAttributesValues(objBol);

}
else
{
TextBox txtname = edititem.FindControl("TextBox1") as TextBox;
objBol.attributes_id = -1;
objBol.attributes_name = txtname.Text.Trim();
int retval= objBll.Bll_InsUpdAttributes(objBol);
if (retval == -1)
{

}
else {
lblmsg.Text = "";
}

}
}


b.)Update: protected void RadGridAttributes_UpdateCommand(object source, GridCommandEventArgs e)
{ GridEditableItem edititem = e.Item as GridEditableItem;
GridDataItem item = e.Item as GridDataItem;
if ("Attributes_values".Equals(e.Item.OwnerTableView.Name))
{
TextBox txtname = edititem.FindControl("TextBox2") as TextBox;
objBol.attributes_values_id = Convert.ToInt32(e.Item .OwnerTableView.DataKeyValues [e.Item.ItemIndex]["attributes_values_id"]);
objBol.attributes_values_name = txtname.Text.Trim();
objBol.attributes_id = -1;
objBll.Bll_InsUpdAttributesValues(objBol);

}
else
{
TextBox txtname = edititem.FindControl("TextBox1") as TextBox;
objBol.attributes_id =Convert .ToInt32 ( RadGridAttributes .MasterTableView .DataKeyValues[e.Item .ItemIndex ] ["attributes_id"]);
objBol.attributes_name = txtname.Text.Trim();
int retval= objBll.Bll_InsUpdAttributes(objBol);
if (retval == -1)
{
lblmsg.Text = "Product Type Exists";
}
else
{
lblmsg.Text = "";
}
}
}

c.)Delete: protected void RadGridAttributes_DeleteCommand(object source, GridCommandEventArgs e)
{
if ("Attributes_values".Equals(e.Item.OwnerTableView.Name))
{
try
{
int attributesid;
attributesid = Convert.ToInt32(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["attributes_values_id"]);
objBll.BLL_DeleteAttributesValues(attributesid);
}
catch(Exception)
{


}

}
else
{
try
{
int attributes_id;
attributes_id = Convert.ToInt32(RadGridAttributes.MasterTableView.DataKeyValues[e.Item.ItemIndex]["attributes_id"]);
objBll.BLL_DeleteAttributes(attributes_id);
}
catch (Exception)
{


}
}
}
**************
10.) Datalist Edit command:

Int32 productsimageId = Convert.ToInt32(DlistProducts.DataKeys[e.Item.ItemIndex]);

11.)Delete files from folders:
datalist delete command:

Int32 productsimageId = Convert.ToInt32(DlistProducts.DataKeys[e.Item.ItemIndex]);
int retval= objBll.BLL_DeleteProductsImages(productsimageId);
if (retval > 0)
{
string strIconpath = "~/ProductsImages/Icon/" + productsimageId + ".jpg";
string strmediumpath = "~/ProductsImages/Medium/" + productsimageId + ".jpg";
string strlargepath = "~/ProductsImages/Large/" + productsimageId + ".jpg";
System.IO.File.Delete(Server.MapPath(strIconpath));
System.IO.File.Delete(Server.MapPath(strmediumpath));
System.IO.File.Delete(Server.MapPath(strlargepath));
}
***************
12.)Master table view only of radgrid:

a.)
Insert:
click on addcolour of top:

GridEditableItem edititem = e.Item as GridEditableItem;
TextBox textColourName = edititem.FindControl("textColourName") as TextBox;
objBol.ColourID = -1;
objBol.Colour_name = textColourName.Text.Trim();
objBol.Image_path = "";
int retval= objBll.BLL_InsUpdColour(objBol);

b.)Update:

GridEditableItem edititem = e.Item as GridEditableItem;
TextBox textColourName = edititem.FindControl("textColourName") as TextBox;
objBol.ColourID =Convert .ToInt32 ( RadgridDisplayColour .MasterTableView .DataKeyValues [e.Item.ItemIndex ]["ColourID"]);
objBol.Colour_name = textColourName.Text.Trim();
objBol.Image_path = "";

c.) Delete:

int colourID;
colourID = Convert.ToInt32(RadgridDisplayColour.MasterTableView.DataKeyValues[e.Item.ItemIndex]["ColourID"]);
objBll.BLL_DeleteColour(colourID);
RadgridDisplayColour.Rebind();

***************
13.) Radgrid Calendar value Insert:

objBol.Promotion_id = -1;
objBol.Promotion_name = (e.Item.FindControl("txtPromotionName") as TextBox).Text.Trim();
objBol.Promotion_code = (e.Item.FindControl("txtPromotionCode") as TextBox).Text.Trim();
objBol.Promotion_discount_value = Convert.ToDecimal((e.Item.FindControl("txtDiscountValue") as TextBox).Text.Trim());
objBol.Promotion_description = (e.Item.FindControl("txtDescription") as TextBox).Text.Trim();
RadDatePicker StrtDate = (RadDatePicker)e.Item.FindControl("txtPstartDate");
if (StrtDate != null)
{
objBol .Promotion_stardate = ((DateTime)StrtDate.SelectedDate);
}
RadDatePicker EndDate = (RadDatePicker)e.Item.FindControl("txtPEndDate");
if (EndDate != null)
{
objBol.Promotion_enddate = ((DateTime)EndDate.SelectedDate);
}
CheckBox chkactive = (CheckBox)e.Item.FindControl("chkPactive");
if (chkactive.Checked == true)
{
objBol.Promotion_active = true;
}
else
{
objBol.Promotion_active = false;
}

******************
14.)RadEditor Values Pick Up:

objBol.EmailID = Convert .ToInt32 (ViewState["EmailID"]);
objBol.Sender = textSender.Text.Trim();
objBol.Subject = textSubject.SelectedValue;
objBol.Header = "";
objBol.Body = RadBody.Html;
objBol.Footer = RadFooter.Html;

26.12.08

To Receive Free Sms in your Mobile Daily

http://www.today-sms.blogspot.com/

Mcsd for microsoft dot.net certification

http://career-assessments.blogspot.com/2008/02/mcsd-for-microsoft-net-certification.html

Projects with source code

http://funnydotnet.blogspot.com/2008/12/projects-with-source-code.html

23.12.08

Remove last character from string

Remove last character from string.
----------------------------------
Got it ...
var myStr = "One, Two, Three, Four,"
var strLen = myStr.length;
myStr = myStr.slice(0,strLen-1);
alert (myStr);

15.12.08

listview 3.5 paging code

protected void LstvwProducts_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{
this.DataPager1.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
DisplayProducts();
}

26.10.08

Validators and someuseful data

REGULAR EXPRESSION

Name:Regular Expression validator: user not to enter numeric values in textbox and special character.
([A-Za-z]+[ ])*([A-Za-z]+)*
---------------------------------
Postcode:Regular Expression Validator :user not to enter only special characters.

([A-Za-z]+[0-9])*([A-Za-z]+)*

([A-Za-z]+[0-9])*([A-Za-z]+[0-9])*
-----------------------------------------
Regular Expression for Postcode:
([A-Za-z0-9])*
---------------------------------
mobile number:regular expression for
([0-90-9]+[-])*([0-90-9]+)*
-----------------------------------
mobile number:regular expression for
([0-90-9]+[-])*([0-90-9]+)*
--------------------------------------------------------

mobile number:regular expression with space and hyphen
([0-9]+[- ])*([0-9]+)*
--------------------------------------------------------
Card Number Regular Expression:

([0-9])*
==========================================================
Password field: enter less than 5 character

----------------------------------
COLLATE SQL_LATIN1_General_CP1_CS_AS
-----------------------------------------

17.7.08

Access CSS in a code behind then use the following code

HtmlLink cssLink = new HtmlLink();
cssLink.Href = "%CSS FILE URL HERE%";
cssLink.Attributes.Add( "rel", "stylesheet" );
cssLink.Attributes.Add("type", "text/css");
Master.Page.Header.Controls.Add(cssLink);

12.7.08

How do I access an iFrame's source's variable from javascript??

document.getElementById('FrameName').contentDocument.getElementById('VarName').innerHTML

so simple, yet so hard to discover lol...

30.6.08

Setting meta tags for content pages in ASP.NET 2.0

If you set the meta tags in the master page, all your pages will have the same meta tags.

Dim metaTag As New HtmlMeta
Dim HeadTag As HtmlHead = CType(Page.Header, HtmlHead)
metaTag.Attributes.Add("name", "description")
metaTag.Attributes.Add("content", "your description goes here")
HeadTag.Controls.Add(metaTag)
metaTag = New HtmlMeta
metaTag.Attributes.Add("name", "keywords")
metaTag.Attributes.Add("content", "your keyword go here")
HeadTag.Controls.Add(metaTag)

Insert and Update Query

IF EXISTS(
SELECT 1
FROM MY_TABLE
WHERE ITEM='somevalue' AND ENTERDATE='12/31/1999')
--Update Statement
UPDATE MY_TABLE
SET ITEM='anothervalue'
WHERE ITEM='somevalue' AND ENTERDATE='12/31/1999'
ELSE
--Insert Statement
INSERT INTO MY_TABLE
(ITEM, ENTERDATE)
VALUES
('somevalue', '12/31/1999')

Print button with javascript - fast and simple solution

The simplest way to print a web form is to use client side javascript. To print a web page, you can use code like this:

<input type="button" value="Print" onclick="window.print();">

This HTML code will return a Print button like bellow. You can click it to print this page.


for more information see this link :