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();
}
}
Monday, June 15, 2009
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("");
////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);
}
}
{
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("
////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
Subscribe to:
Posts (Atom)