String militaryTimeFormat = "HH:mm";
String input = DateTime.Now.ToString(militaryTimeFormat);
DateTime time = DateTime.ParseExact(input, militaryTimeFormat, null);
string militaryTime = "06/12/2008 20:30";
IFormatProvider culture = new System.Globalization.CultureInfo("en-US", true);
DateTime militaryDate =DateTime.Parse(militaryTime, culture, System.Globalization.DateTimeStyles.NoCurrentDateDefault);
string g=DateTime.Now.ToString("dd/MM/yyyy HH:mm");
string h = DateTime.Now.ToString("HH:mm");
Wednesday, June 4, 2008
Paging Advantage of Datalist Control in asp.net with c#
HTML Coding :

Server Side Coding: c#
SqlConnection scn = new SqlConnection("Data Source=.;Initial Catalog=iptv_database;Integrated Security=True");
int Start;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ViewState["Start"] = 0;
BindData();
}
}
void BindData()
{
SqlDataAdapter da = new SqlDataAdapter("select * from addprogram", scn);
DataSet ds= new DataSet();
Start = (int)ViewState["Start"];
ViewState["Size"] = 2;
da.Fill(ds,Start,(int)ViewState["Size"], "addprogram");
DataList1.DataSource = ds;
DataList1.DataBind();
}
protected void lnkPrevious_Click(object sender, EventArgs e)
{
Start = (int)ViewState["Start"] - (int)ViewState["Size"];
ViewState["Start"] = Start;
if (Start <= 0)
{
ViewState["Start"] = 0;
}
BindData();
}
protected void lnkNext_Click(object sender, EventArgs e)
{
int count = DataList1.Items.Count;
Start = (int)ViewState["Start"] + (int)ViewState["Size"];
ViewState["Start"] = Start;
if (count <(int)ViewState["Size"])
{
ViewState["Start"] = (int)ViewState["Start"] + (int)ViewState["Size"];
Start = (int)ViewState["Start"];
}

Server Side Coding: c#
SqlConnection scn = new SqlConnection("Data Source=.;Initial Catalog=iptv_database;Integrated Security=True");
int Start;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ViewState["Start"] = 0;
BindData();
}
}
void BindData()
{
SqlDataAdapter da = new SqlDataAdapter("select * from addprogram", scn);
DataSet ds= new DataSet();
Start = (int)ViewState["Start"];
ViewState["Size"] = 2;
da.Fill(ds,Start,(int)ViewState["Size"], "addprogram");
DataList1.DataSource = ds;
DataList1.DataBind();
}
protected void lnkPrevious_Click(object sender, EventArgs e)
{
Start = (int)ViewState["Start"] - (int)ViewState["Size"];
ViewState["Start"] = Start;
if (Start <= 0)
{
ViewState["Start"] = 0;
}
BindData();
}
protected void lnkNext_Click(object sender, EventArgs e)
{
int count = DataList1.Items.Count;
Start = (int)ViewState["Start"] + (int)ViewState["Size"];
ViewState["Start"] = Start;
if (count <(int)ViewState["Size"])
{
ViewState["Start"] = (int)ViewState["Start"] + (int)ViewState["Size"];
Start = (int)ViewState["Start"];
}
Saturday, May 31, 2008
Creating Controls at Runtime
TextBox txt1 = new TextBox();
TextBox txt2 = new TextBox();
txt1.Text = "This is the textbox inside the placeholder";
txt2.Text = "This is the textbox inside the panel";
txt1.Style["width"] = "250px";
txt2.Style["width"] = "250px";
PlaceHolder1.Controls.Add(txt1);
Panel1.Controls.Add(txt2);
TextBox txt2 = new TextBox();
txt1.Text = "This is the textbox inside the placeholder";
txt2.Text = "This is the textbox inside the panel";
txt1.Style["width"] = "250px";
txt2.Style["width"] = "250px";
PlaceHolder1.Controls.Add(txt1);
Panel1.Controls.Add(txt2);
Friday, May 9, 2008
VideoStreaming in asp.net with c#
using System.IO;
using System.IO.Compression;
FileStream sourceFile;
GZipStream compStream;
FileStream destFile;
protected void btnCompress_Click1(object sender, EventArgs e)
{
if (File1.PostedFile != null)
{
txtSource.Text = File1.PostedFile.FileName.ToString();
}
sourceFile = File.OpenRead(txtSource.Text);
destFile = File.Create(txtDestination.Text);
compStream = new GZipStream(destFile, CompressionMode.Compress);
int theByte = sourceFile.ReadByte();
while (theByte != -1)
{
compStream.WriteByte((byte)theByte);
theByte = sourceFile.ReadByte();
}
sourceFile.Close();
destFile.Close();
}
protected void btnDecompress_Click(object sender, EventArgs e)
{
if (File1.PostedFile != null)
{
txtSource.Text = File1.PostedFile.FileName.ToString();
}
string srcFile = txtSource.Text;
string dstFile = txtDestination.Text;
FileStream fsIn = null; // will open and read the srcFile
FileStream fsOut = null; // will be used by the GZipStream for output to the dstFile
GZipStream gzip = null;
const int bufferSize = 4096;
byte[] buffer = new byte[bufferSize];
int count = 0;
{
fsIn = new FileStream(srcFile, FileMode.Open, FileAccess.Read, FileShare.Read);
fsOut = new FileStream(dstFile, FileMode.Create, FileAccess.Write, FileShare.None);
gzip = new GZipStream(fsIn, CompressionMode.Decompress, true);
while (true)
{
count = gzip.Read(buffer, 0, bufferSize);
if (count != 0)
{
fsOut.Write(buffer, 0, count);
}
if (count != bufferSize)
{
// have reached the end
break;
}
}
}
}
}
using System.IO.Compression;
FileStream sourceFile;
GZipStream compStream;
FileStream destFile;
protected void btnCompress_Click1(object sender, EventArgs e)
{
if (File1.PostedFile != null)
{
txtSource.Text = File1.PostedFile.FileName.ToString();
}
sourceFile = File.OpenRead(txtSource.Text);
destFile = File.Create(txtDestination.Text);
compStream = new GZipStream(destFile, CompressionMode.Compress);
int theByte = sourceFile.ReadByte();
while (theByte != -1)
{
compStream.WriteByte((byte)theByte);
theByte = sourceFile.ReadByte();
}
sourceFile.Close();
destFile.Close();
}
protected void btnDecompress_Click(object sender, EventArgs e)
{
if (File1.PostedFile != null)
{
txtSource.Text = File1.PostedFile.FileName.ToString();
}
string srcFile = txtSource.Text;
string dstFile = txtDestination.Text;
FileStream fsIn = null; // will open and read the srcFile
FileStream fsOut = null; // will be used by the GZipStream for output to the dstFile
GZipStream gzip = null;
const int bufferSize = 4096;
byte[] buffer = new byte[bufferSize];
int count = 0;
{
fsIn = new FileStream(srcFile, FileMode.Open, FileAccess.Read, FileShare.Read);
fsOut = new FileStream(dstFile, FileMode.Create, FileAccess.Write, FileShare.None);
gzip = new GZipStream(fsIn, CompressionMode.Decompress, true);
while (true)
{
count = gzip.Read(buffer, 0, bufferSize);
if (count != 0)
{
fsOut.Write(buffer, 0, count);
}
if (count != bufferSize)
{
// have reached the end
break;
}
}
}
}
}
Monday, April 28, 2008
RSS Feeds in asp.net with c#
A simple Program to view xml in Datagrid
using System.Xml;
XmlTextReader reader = new XmlTextReader("http://msdn.microsoft.com/rss.xml");
// creates a new instance of DataSet
DataSet ds = new DataSet();
// Reads the xml into the dataset
ds.ReadXml(reader);
// Assigns the data table to the datagrid
myDataGrid.DataSource = ds.Tables[2];
// Binds the datagrid
myDataGrid.DataBind();
using System.Xml;
XmlTextReader reader = new XmlTextReader("http://msdn.microsoft.com/rss.xml");
// creates a new instance of DataSet
DataSet ds = new DataSet();
// Reads the xml into the dataset
ds.ReadXml(reader);
// Assigns the data table to the datagrid
myDataGrid.DataSource = ds.Tables[2];
// Binds the datagrid
myDataGrid.DataBind();
Subscribe to:
Comments (Atom)



