using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Linq.Mapping;

public partial class Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public void showgridview()
    {

        DataClassesDataContext dc = new DataClassesDataContext();

        var q =
        from a in dc.GetTable<bio>()
        select a;
        GridView1.DataSource = q;
        //GridView1.DataSource = dc.GetTable<bio>();
        GridView1.DataBind();
    }
    public void whereQuery()
    {
        DataClassesDataContext dc = new DataClassesDataContext();
        var q =
        from a in dc.GetTable<bio>()
        where a.name == TextBox3.Text
        select a;
        GridView1.DataSource = q;
        GridView1.DataBind();

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        whereQuery();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        showgridview();
    }

    private void Insert()
    {
        DataClassesDataContext dc = new DataClassesDataContext();
        bio obj = new bio();
        obj.name = TextBox3.Text;
        obj.passw = TextBox5.Text;
        obj.fname = TextBox4.Text;
        dc.bios.InsertOnSubmit(obj);
        dc.SubmitChanges();
        showgridview();
    }


    protected void Button3_Click(object sender, EventArgs e)
    {
        Insert();
    }

    private void Update()
    {
        DataClassesDataContext dc = new DataClassesDataContext();
        bio objbio = dc.bios.Single(bio => bio.name == TextBox3.Text);
        objbio.passw = TextBox5.Text;
        objbio.fname = TextBox4.Text;
        dc.SubmitChanges();

    }

    protected void Button4_Click(object sender, EventArgs e)
    {
        Update();
        showgridview();
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        TextBox3.Text = GridView1.SelectedRow.Cells[2].Text;
        TextBox5.Text = GridView1.SelectedRow.Cells[3].Text;
        TextBox4.Text = GridView1.SelectedRow.Cells[4].Text;
    }


    private void Delete()
    {
        DataClassesDataContext dc = new DataClassesDataContext();
        bio obb = dc.bios.Single(bio => bio.name == TextBox3.Text);
        dc.bios.DeleteOnSubmit(obb);
        dc.SubmitChanges();

    }

    protected void Button5_Click(object sender, EventArgs e)
    {
        Delete();
        showgridview();
    }



    protected void Button6_Click(object sender, EventArgs e)
    {
        //Linq to SQL
        DataClassesDataContext dc = new DataClassesDataContext();
        var biofee = from bio in dc.bios
                     join fee in dc.fees
                     on bio.id equals fee.id
                     select new { bio.name, bio.fname, fee.Address };
        GridView1.DataSource = biofee;
        GridView1.DataBind();
    }


    protected void Button7_Click(object sender, EventArgs e)
    {
        DataClassesDataContext dc = new DataClassesDataContext();
        var query = dc.bios.Join(dc.fees, r => r.id, p => p.id, (r, p) => new { r.name, r.fname, p.Address });
        GridView1.DataSource = query;
        GridView1.DataBind();
    }
    protected void Button8_Click(object sender, EventArgs e)
    {
        List<Test> l = new List<Test>();
        Test t = new Test();
        t.name = "Hussain";
        l.Add(t);
        GridView1.DataSource = from a in l select a;
        GridView1.DataBind();

    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.