protected void Page_Load(object sender, EventArgs e)
{
LoadGrid();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
ViewState["Id"] = GridView1.SelectedDataKey["Id"];
TextBox1.Text = GridView1.SelectedRow.Cells[2].Text;
}
protected void Button1_Click(object sender, EventArgs e)
{
DataClassesDataContext db = new DataClassesDataContext();
if (ViewState["Id"] == null)
{//Save
Temp t = new Temp();
t.Name = TextBox1.Text;
db.Temps.InsertOnSubmit(t);
db.SubmitChanges();
TextBox1.Text = "";
}
else
{
//Update
Temp t = db.Temps.Single(b=>b.Id.Equals(ViewState["Id"]));
t.Name=TextBox1.Text;
db.SubmitChanges();
TextBox1.Text = "";
}
LoadGrid();
}
public void LoadGrid()
{
DataClassesDataContext db = new DataClassesDataContext();
var p = from b in db.Temps
select new { b.Id, b.Name };
GridView1.DataSource = p;
GridView1.DataBind();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
DataClassesDataContext db = new DataClassesDataContext();
string i = GridView1.SelectedRow.Cells[1].Text;
Temp t = db.Temps.Single(b => b.Id.Equals(Convert.ToInt32(i)));
db.Temps.DeleteOnSubmit(t);
db.SubmitChanges();
LoadGrid();
}
Search
Thursday, August 12, 2010
Wednesday, August 11, 2010
Linq:- LeftOuterJoin
from t in Table0
join t0 in Table1 on t.Id equals t0.EventAttendeeId into t0_join
from t0 in t0_join.DefaultIfEmpty()
join t1 in Table2 on t.AttendeeId equals t1.Id into t1_join
from t1 in t1_join.DefaultIfEmpty()
join t2 in Table3 on t.AttendeeCompanyId equals t2.Id into t2_join
from t2 in t2_join.DefaultIfEmpty()
select new
{
Comments=t0.Comments
}
join t0 in Table1 on t.Id equals t0.EventAttendeeId into t0_join
from t0 in t0_join.DefaultIfEmpty()
join t1 in Table2 on t.AttendeeId equals t1.Id into t1_join
from t1 in t1_join.DefaultIfEmpty()
join t2 in Table3 on t.AttendeeCompanyId equals t2.Id into t2_join
from t2 in t2_join.DefaultIfEmpty()
select new
{
Comments=t0.Comments
}
Linq:- LeftOuterJoin_Count_GroupBy
from dept in Table1
join employee in Table2
on dept.Id equals employee.RoomTypeId
group new{dept,employee} by new
{
dept.Name,
dept.Limit,
employee.RoomTypeId
} into g
where g.Count() > 0
select new
{
d=g.Count(),
g.Key.Name,
g.Key.Limit,
}
join employee in Table2
on dept.Id equals employee.RoomTypeId
group new{dept,employee} by new
{
dept.Name,
dept.Limit,
employee.RoomTypeId
} into g
where g.Count() > 0
select new
{
d=g.Count(),
g.Key.Name,
g.Key.Limit,
}
Subscribe to:
Posts (Atom)