private void ViewAllRoom_Load(object sender, EventArgs e)
{
//This Is Parent Node
TreeNode MainNode = new TreeNode();
MainNode.NodeFont = new Font("Microsoft Sans Serif", 10);
MainNode.Name = "MainName";
MainNode.Text = "All Rooms";
MainNode.ForeColor = Color.Red;
this.treeView1.Nodes.Add(MainNode);
//Next add child Node
ds = da.GetDataTable("SELECT RName FROM RTypeCreation");
foreach (DataRow Parentrow in ds.Tables[0].Rows)
{
TreeNode treenode = new TreeNode((string)Parentrow["RName"]);
MainNode.Nodes.Add(treenode);
treenode.NodeFont = new Font("Microsoft Sans Serif", 10);
treenode.ForeColor = Color.Tan;
}
Friday, January 28, 2011
Monday, January 17, 2011
Create Button at Run Time In C #
for (int i = 0; i < 10; i++)
{
obj = new Button();
obj.Location = new Point(bt, 80);
newname = (btn + i).ToString();
obj.Name = "Table";
obj.Text = newname;
obj.Height = 50;
obj.Width = 80;
obj.Click += new EventHandler(obj_Click);
this.Controls.Add(obj);
bt += 90;
}
{
obj = new Button();
obj.Location = new Point(bt, 80);
newname = (btn + i).ToString();
obj.Name = "Table";
obj.Text = newname;
obj.Height = 50;
obj.Width = 80;
obj.Click += new EventHandler(obj_Click);
this.Controls.Add(obj);
bt += 90;
}
Run Time Created Button Color Change In C#
public void BtnColourChg()
{
DataAccess da = new DataAccess();
try
{
da.OpenConnection();
SqlDataReader dr = da.ExecuteReader("Select tableno from billtotal where status=1");
while (dr.Read())
{
foreach (Control item in this.Controls)
{
if (item is Button)
{
Button b = (Button)item;
if (b.Text == dr[0].ToString())
{
b.BackColor = System.Drawing.Color.Red;
}
}
}
}
}
catch (Exception ex) { }
finally { da.CloseConnection(); }
}
{
DataAccess da = new DataAccess();
try
{
da.OpenConnection();
SqlDataReader dr = da.ExecuteReader("Select tableno from billtotal where status=1");
while (dr.Read())
{
foreach (Control item in this.Controls)
{
if (item is Button)
{
Button b = (Button)item;
if (b.Text == dr[0].ToString())
{
b.BackColor = System.Drawing.Color.Red;
}
}
}
}
}
catch (Exception ex) { }
finally { da.CloseConnection(); }
}
Monday, September 20, 2010
Add Gridview Check Item In Second GridView In Asp .Net
protected void Page_Load(object sender, EventArgs e)
{
BindDropList();
if (!IsPostBack)
{
DataTable dt = new DataTable();
DataColumn dc;
dc = new DataColumn();
dc.ColumnName = "Name";
dt.Columns.Add(dc);
dc = new DataColumn();
dc.ColumnName = "LName";
dt.Columns.Add(dc);
Session["dt"] = dt;
}
}
---------------------------------------------------------------------------------------------------
protected void Button3_Click(object sender, EventArgs e)
{
DataTable dt = (DataTable)Session["dt"];
DataRow dr;
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox ch = (CheckBox)row.FindControl("asd");
if (ch.Checked==true)
{
try
{
dr = dt.NewRow();
dr["Name"] = row.Cells[1].Text;
dr["LName"] = row.Cells[2].Text;
dt.Rows.Add(dr);
}
catch (Exception ex)
{ Response.Write(ex.Message); }
}
}
GridView2.DataSource = dt;
GridView2.DataBind();
}
---------------------------------------------------------------------------------------------------
{
BindDropList();
if (!IsPostBack)
{
DataTable dt = new DataTable();
DataColumn dc;
dc = new DataColumn();
dc.ColumnName = "Name";
dt.Columns.Add(dc);
dc = new DataColumn();
dc.ColumnName = "LName";
dt.Columns.Add(dc);
Session["dt"] = dt;
}
}
---------------------------------------------------------------------------------------------------
protected void Button3_Click(object sender, EventArgs e)
{
DataTable dt = (DataTable)Session["dt"];
DataRow dr;
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox ch = (CheckBox)row.FindControl("asd");
if (ch.Checked==true)
{
try
{
dr = dt.NewRow();
dr["Name"] = row.Cells[1].Text;
dr["LName"] = row.Cells[2].Text;
dt.Rows.Add(dr);
}
catch (Exception ex)
{ Response.Write(ex.Message); }
}
}
GridView2.DataSource = dt;
GridView2.DataBind();
}
---------------------------------------------------------------------------------------------------
Wednesday, July 28, 2010
Dataset Bind to Gridview in Asp .Net With C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string connectionString = WebConfigurationManager.ConnectionStrings["Northwind"].ConnectionString;
string selectSQL = "SELECT ProductID, ProductName, UnitPrice FROM Products";
SqlConnection con = new SqlConnection(connectionString);adapter.Fill(ds, "Products");
SqlCommand cmd = new SqlCommand(selectSQL, con);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
}
Tuesday, July 13, 2010
Printing In Windows Application
private void btn_Print_Click(object sender, EventArgs e)
{
printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument1_PrintPage);
printPreviewDialog1.Document = printDocument1;
printPreviewDialog1.ShowDialog();
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawLine(new Pen(Brushes.Black), new Point(10, 80), new Point(370, 80));
e.Graphics.DrawLine(new Pen(Brushes.Black), new Point(10, 100), new Point(370, 100));
e.Graphics.DrawLine(new Pen(Brushes.Black), new Point(10, 300), new Point(370, 300));
e.Graphics.DrawLine(new Pen(Brushes.Black), new Point(10, 320), new Point(370, 320));
e.Graphics.DrawLine(new Pen(Brushes.Black), new Point(60, 80), new Point(60, 320));
e.Graphics.DrawLine(new Pen(Brushes.Black), new Point(165, 80), new Point(165, 320));
e.Graphics.DrawLine(new Pen(Brushes.Black), new Point(230, 80), new Point(230, 320));
e.Graphics.DrawLine(new Pen(Brushes.Black), new Point(310, 80), new Point(310, 320));
e.Graphics.DrawString("Rameshwar", new Font("Times New Roman", 12F), Brushes.Black, new PointF(10, 50));
e.Graphics.DrawString("Komal", new Font(" Times New Roman", 12F), Brushes.Black, new PointF(15, 80));
e.Graphics.DrawString("Vishal", new Font("Times New Roman", 12F), Brushes.Black, new PointF(70, 80));
e.Graphics.DrawString("Rahul", new Font("Times New Roman", 12F), Brushes.Black, new PointF(170, 80));
}
{
printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument1_PrintPage);
printPreviewDialog1.Document = printDocument1;
printPreviewDialog1.ShowDialog();
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawLine(new Pen(Brushes.Black), new Point(10, 80), new Point(370, 80));
e.Graphics.DrawLine(new Pen(Brushes.Black), new Point(10, 100), new Point(370, 100));
e.Graphics.DrawLine(new Pen(Brushes.Black), new Point(10, 300), new Point(370, 300));
e.Graphics.DrawLine(new Pen(Brushes.Black), new Point(10, 320), new Point(370, 320));
e.Graphics.DrawLine(new Pen(Brushes.Black), new Point(60, 80), new Point(60, 320));
e.Graphics.DrawLine(new Pen(Brushes.Black), new Point(165, 80), new Point(165, 320));
e.Graphics.DrawLine(new Pen(Brushes.Black), new Point(230, 80), new Point(230, 320));
e.Graphics.DrawLine(new Pen(Brushes.Black), new Point(310, 80), new Point(310, 320));
e.Graphics.DrawString("Rameshwar", new Font("Times New Roman", 12F), Brushes.Black, new PointF(10, 50));
e.Graphics.DrawString("Komal", new Font(" Times New Roman", 12F), Brushes.Black, new PointF(15, 80));
e.Graphics.DrawString("Vishal", new Font("Times New Roman", 12F), Brushes.Black, new PointF(70, 80));
e.Graphics.DrawString("Rahul", new Font("Times New Roman", 12F), Brushes.Black, new PointF(170, 80));
}
Sunday, April 11, 2010
windows application Add Combobox in Gridview at run time
this method is use to bind table value in dataset;
public DataTable cmbBindGrid()
{
DataAccess da = new DataAccess();
DataSet ds = new DataSet();
try
{
ds = da.GetDataTable("SELECT MPId,MPName FROM MilkatParkarPK");
return ds.Tables[0];
}
catch (Exception ex) { return ds.Tables[0]; }
}
Then
private void namuna8_Load(object sender, EventArgs e)
{
DataGridViewComboBoxColumn x = new DataGridViewComboBoxColumn();
x.DataSource = cmbBindGrid();
x.DisplayMember = "MPName";
x.ValueMember = "MPId";
x.HeaderText = "ekyeRrspk Ádkj";
x.Name = "Test";
x.Visible = true;
x.Width = 170;
dataGridView1.Columns.Add(x);
}
Subscribe to:
Posts (Atom)