Wednesday, June 24, 2009

Thursday, June 18, 2009

How to use repeater inside of the grid in c#




using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class Default2 : System.Web.UI.Page
{


protected void Page_Load(object sender, EventArgs e)
{
binddata();
}

// Function to bind data in data controls..
public void binddata()
{
// your connection string here
string str = "Data Source=.;Initial Catalog=master;Integrated Security=True";
SqlConnection con = new SqlConnection(str);
DataSet ds = new DataSet();
// name of your stored procedure,
SqlDataAdapter da = new SqlDataAdapter("getCompNews", con);
da.Fill(ds);

ds.Relations.Add("InnerVal",
ds.Tables[0].Columns["compname"],
// making a relation between two tables.
ds.Tables[1].Columns["compname"]);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lnkMore = (LinkButton)e.Row.FindControl("link");
Label lbl = (Label)e.Row.FindControl("Label1");
lnkMore.PostBackUrl = "~/Company.aspx?cmp=" + lbl.Text;
}
}
}

Wednesday, June 17, 2009

Using checkbox in the gridview using c#











using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
SqlConnection cn;
SqlCommand cmd;
SqlDataAdapter da;
DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{
cn = new SqlConnection("Data Source=.;Initial Catalog=master;Integrated Security=True");
if (!IsPostBack)
{
pg_load();
}
}

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
StringBuilder str = new StringBuilder();


int i = 0;


//for (int i = 0; i < GridView1.Rows.Count; i++)
//{
// GridViewRow row = GridView1.Rows[i];
// bool isChecked = ((CheckBox)row.FindControl("chkSelect")).Checked;

// if (isChecked)
// {


foreach (GridViewRow gvr in GridView1.Rows)
{
CheckBox chk = (CheckBox)gvr.FindControl("chkSelect");
if (chk.Checked==true)
{

str.Append(" "+GridView1.Rows[i].Cells[2].Text);
i++;
}
}


// prints out the result

Response.Write(str.ToString());
}
void pg_load()
{
cmd = new SqlCommand("select * from gridcheck", cn);
cmd.CommandType = CommandType.Text;
da = new SqlDataAdapter(cmd);
dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}



Friday, June 12, 2009

How to use Repeater in c#



protected void lbtncreate_Click(object sender, EventArgs e)
{

multiview.ActiveViewIndex = 1;
cmd=new SqlCommand("select title from " + Session["a"] + "", con);
da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
ArrayList al = new ArrayList();
for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
al.Insert(i, ds.Tables[0].Rows[i][0].ToString());
}
repeater.DataSource = al;
repeater.DataBind();
}

How to get the word count and highlighting the word in a stream

private void word_count_Load(object sender, EventArgs e)
{
StreamReader sr = new StreamReader(Form1.currpath + "sampl.txt");
//richTextBox1.Text = sr.ReadLine();
string contents = sr.ReadToEnd();
StreamWriter sw = new StreamWriter("richTextBox1");
sw.Write(contents);
sw.Close();
richTextBox1.Text = contents;
sr.Close();
label2.Text=Form1.query.ToString();
//string[] str = richTextBox1.Text.Split('');
string text = contents.ToString();

string word = label2.Text.ToString();
r = new Regex(@"\b" + word + @"\b", RegexOptions.IgnoreCase);
MatchCollection mc = r.Matches(contents);
a = mc.Count;
//int a = str.Length;
textBox1.Text = a.ToString();
//int b = label2.Text.Length;
//int d = richTextBox1.Find(label2.Text.ToString());
////int a = richTextBox1.Find(""); <br /> ////int b = richTextBox1.Find("");
////int c = d + b;
//richTextBox1.Select(d, b);
//richTextBox1.SelectionColor = Color.Goldenrod;
//richTextBox1.SelectionFont = new Font(richTextBox1.SelectionFont, FontStyle.Bold);



string zoek = label2.Text;

int index = richTextBox1.Text.IndexOf(zoek);
while(index != -1)
{
richTextBox1.Select(index, zoek.Length);
richTextBox1.SelectionColor = Color.Red;
index = richTextBox1.Text.IndexOf(zoek, index + zoek.Length);
}



}

Thursday, June 11, 2009

Wednesday, June 10, 2009

Tuesday, June 9, 2009

Saturday, May 30, 2009

Wednesday, May 6, 2009

usage of repeater in c#





code:


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
SqlConnection con;

protected void Page_Load(object sender, EventArgs e)
{
con = new SqlConnection("Data Source=.;Initial Catalog=Proj_saha;Integrated Security=True ");
SqlCommand cmd = new SqlCommand("SELECT * FROM history", con);
con.Open();

//place table information into DataSet
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
rptList.DataSource = ds;
rptList.DataBind();
con.Close();
}
}



design:-





Wednesday, April 1, 2009

Dynamic tree view creation using c#















using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;
using System.Data.SqlClient;


public partial class Default2 : System.Web.UI.Page
{
SqlCommand cmd;
SqlConnection cn;
//SqlDataReader dr;

protected void Page_Load(object sender, EventArgs e)
{

fill_Tree2();

}


void fill_Tree2()
{



DataSet PrSet = PDataset("Select productcode from ccc group by productcode");

TreeView1.Nodes.Clear();

foreach (DataRow dr in PrSet.Tables[0].Rows)
{

TreeNode tnParent = new TreeNode();

tnParent.Text = dr["productcode"].ToString();

//tnParent.Value = dr["ParentID"].ToString();
//tnParent.PopulateOnDemand = true;

TreeView1.Nodes.Add(tnParent);

FillChild(tnParent, tnParent.Value);
//FillChild1(tnParent, tnParent.Value);


tnParent.ToolTip = "Click to get Child";

//tnParent.SelectAction = TreeNodeSelectAction.SelectExpand;



tnParent.CollapseAll();
//tnParent.Selected = true;

}




}

public void FillChild(TreeNode parent, string ParentId)
{

DataSet ds = PDataset("Select * from ccc where productcode =" + ParentId+" order by productcode");

parent.ChildNodes.Clear();

foreach (DataRow dr in ds.Tables[0].Rows)
{

TreeNode child = new TreeNode();

child.Text = dr["productname"].ToString().Trim();
child.NavigateUrl = dr["url"].ToString().Trim();

//child.Value = dr["ChildId"].ToString().Trim();

if (child.ChildNodes.Count == 0)
{

child.PopulateOnDemand = true;

}

child.ToolTip = "Click to get Child";

child.SelectAction = TreeNodeSelectAction.SelectExpand;

child.CollapseAll();

parent.ChildNodes.Add(child);


}

}


//public void FillChild1(TreeNode parent, string ParentId)
//{

// DataSet ds = PDataset("Select * from ccc where productcode =" + ParentId);

// parent.ChildNodes.Clear();

// foreach (DataRow dr in ds.Tables[0].Rows)
// {

// TreeNode child1 = new TreeNode();

// child1.NavigateUrl = dr["url"].ToString().Trim();

// //child.Value = dr["ChildId"].ToString().Trim();

// if (child1.ChildNodes.Count == 0)
// {

// child1.PopulateOnDemand = true;

// }

// child1.ToolTip = "Click to get Child";

// child1.SelectAction = TreeNodeSelectAction.SelectExpand;

// child1.CollapseAll();

// parent.ChildNodes.Add(child1);

// }

//}




protected DataSet PDataset(string Select_Statement)
{

SqlConnection SqlCon = new SqlConnection("Data Source=.;Initial Catalog=govind;Integrated Security=True");

SqlDataAdapter ad = new SqlDataAdapter(Select_Statement, SqlCon);

DataSet ds = new DataSet();

ad.Fill(ds);

return ds;



}
protected void Button1_Click(object sender, EventArgs e)
{
cn = new SqlConnection("Data Source=.;Initial Catalog=govind;Integrated Security=True");
cmd= new SqlCommand("insert into ccc values('"+DropDownList1.SelectedItem.Text+"','"+TextBox1.Text+"','"+TextBox2.Text+"')",cn);
cmd.CommandType=CommandType.Text;
cn.Open();

cmd.ExecuteNonQuery();
fill_Tree2();
}
}