This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Showing posts with label c#. Show all posts
Showing posts with label c#. Show all posts

Sunday, August 28, 2011

Cookies In Client Side asp.net with C#


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.Cookies["Username"] != null)
Txtusername.Text = Response.Cookies["Username"].Value;
Txtusername.Attributes.Add("value", Request.Cookies["Username"].Value);
if (Request.Cookies["password"] != null)
Txtpassword.Attributes.Add("value", Request.Cookies["password"].Value);
if ((Request.Cookies["username"] != null) && (Request.Cookies["password"] != null))
Chkrember.Checked = true;
}
}
protected void Btnsubmit_Click(object sender, EventArgs e)
{
if ((this.Chkrember.Checked))
{
if ((Request.Browser.Cookies))
{
Response.Cookies["username"].Value = Txtusername.Text;
Response.Cookies["username"].Expires = DateTime.Now.AddYears(20);
Response.Cookies["password"].Value = Txtpassword.Text;
Response.Cookies["password"].Expires = DateTime.Now.AddYears(20);
}
else
{
Response.Cookies["username"].Expires = DateTime.Now.AddYears(-20);
Response.Cookies["password"].Expires = DateTime.Now.AddYears(-20);
} }
}



How can I bind to a DataSet?
DataSet ds = GetDataSet();
DataView view = ds.Tables[0].DefaultView;
SmoothLineChart chart = new SmoothLineChart();
chart.Legend = "Value 1";
chart.DataSource = view;
chart.DataXValueField = "Description";
chart.DataYValueField = "Value1";
chart.DataBind();
ChartControl1.Charts.Add(chart);
ChartControl1.RedrawChart();

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
LoadChartData();
}
}


private void LoadChartData()
{
string constr = @"Server=TestServer; Database=SampleDatabase; uid=sa; pwd=123;";
string query = "SELECT c.CategoryID, c.CategoryName, " +
" Count(p.UnitPrice) AS 'TotalProducts' " +
" FROM Categories c " +
" INNER JOIN Products p ON c.CategoryID = p.CategoryID " +
" GROUP BY c.CategoryID, c.CategoryName";

SqlDataAdapter da = new SqlDataAdapter(query, constr);
DataTable table = new DataTable();
da.Fill(table);

DataView dv = table.DefaultView;

Chart1.Series["Series1"].Points.DataBindXY(dv, "CategoryName", dv, "TotalProducts");
Chart2.Series["Series1"].Points.DataBindXY(dv, "CategoryName", dv, "TotalProducts");
}

Drop Down List in Multiple Selected Items

For example if u select in country and it will come state and city
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class _Default : System.Web.UI.Page
{
//Class1 obj = new Class1();
private string strconnection = "Data Source=NCORE-8;Initial Catalog=dropdown;Trusted_Connection=true;Integrated Security=True ";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindCountryDropdown();
}
}
protected void BindCountryDropdown()
{
SqlConnection con = new SqlConnection(strconnection);
con.Open();

SqlCommand cmd = new SqlCommand("select * from Country", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
ddlCountry.DataSource = ds;
ddlCountry.DataTextField = "CountryName";
ddlCountry.DataValueField = "CountryID";
ddlCountry.DataBind();
ddlCountry.Items.Insert(0, new ListItem("--Select--", "0"));
ddlState.Items.Insert(0, new ListItem("--Select--", "0"));
ddlCity.Items.Insert(0, new ListItem("--Select--", "0"));

}

protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
{
int CountryID = Convert.ToInt32(ddlCountry.SelectedValue);
SqlConnection con = new SqlConnection(strconnection);
con.Open();


SqlCommand cmd = new SqlCommand("select * from State where CountryID=" + CountryID, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();

da.Fill(ds);
con.Close();

ddlState.DataSource = ds;
ddlState.DataTextField = "StateName";
ddlState.DataValueField = "StateID";
ddlState.DataBind();
ddlState.Items.Insert(0, new ListItem("--Select--", "0"));

if (ddlState.SelectedValue == "0")
{
ddlCity.Items.Clear();
ddlCity.Items.Insert(0, new ListItem("--Select--", "0"));
}
}


protected void ddlState_SelectedIndexChanged(object sender, EventArgs e)
{
int StateID = Convert.ToInt32(ddlState.SelectedValue);
SqlConnection con = new SqlConnection(strconnection);
con.Open();

SqlCommand cmd = new SqlCommand("select * from City where StateID=" + StateID, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();

da.Fill(ds);
con.Close();

ddlCity.DataSource = ds;
ddlCity.DataTextField = "CityName";
ddlCity.DataValueField = "CityID";
ddlCity.DataBind();
ddlCity.Items.Insert(0, new ListItem("--Select--", "0"));
}
}

Webconfig




App code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;

///


/// Summary description for Class1
///

public class Class1
{
public string CountryName, StateName, CityName , cs;
public int CountryId, StateID, CityID;
public Class1()
{
cs = System.Configuration.ConfigurationManager.AppSettings["Connection"].ToString();
}


}