We help IT Professionals succeed at work.
Get Started

ASP.net C#, entity, linq

Radim88
Radim88 asked
on
417 Views
Last Modified: 2012-06-21
Hello,

I am trying to create easy web page, but i still have problems with postback. There is one gridview and one details view and easy search (textbox). If I write something into textbox It will find it for me and shows it in the gridview, but if I click the select on the gridview, gridview loads back from previous state. I am addidng code:

 
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.SqlClient;



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

        BindData();  
        if (!IsPostBack)
        {

                   

        }
    }
    
   

    private void BindData()
    {

        DataClassesDataContext myCont = new DataClassesDataContext();

        var query = from c in myCont.Customers
                    select c;

        GridView1.DataSource = query.ToList();
        GridView1.DataBind();

    }


   
    protected void DetailsView1_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
    {
        GridView1.DataBind();
    }
    protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
    {
        GridView1.DataBind();
    }
    protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
    {
        GridView1.DataBind();
    }
    protected void DetailsView1_ItemDeleting(object sender, DetailsViewDeleteEventArgs e)
    {
        GridView1.DataBind();
    }
    protected void DetailsView1_ItemDeleted(object sender, DetailsViewDeletedEventArgs e)
    {
        GridView1.DataBind();
    }
    protected void DetailsView1_ItemCreated(object sender, EventArgs e)
    {
        GridView1.DataBind();
    }
    protected void DetailsView1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
    {
        GridView1.DataBind();
    }
    

    
    
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
       
        DataClassesDataContext myCont = new DataClassesDataContext();
        var query2 = from c in myCont.Customers
                     where c.Fname.StartsWith(TextBox2.Text)
                     //where  SqlMethods.Like( c.Fname, firstName)
                     select c;

        GridView1.DataSource = query2;
        GridView1.DataBind();
        TextBox2.Text = "";
    }

    protected void GridView1_PageIndexChanged(object sender, EventArgs e)
    {
        GridView1.DataBind();
    }

    protected void TextBox3_TextChanged(object sender, EventArgs e)
    {

    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        

        
        DataClassesDataContext myCont = new DataClassesDataContext();
        var query2 = from c in myCont.Customers
                     where c.Lname.StartsWith(TextBox3.Text)
                     //where  SqlMethods.Like( c.Fname, firstName)
                     select c;

        GridView1.DataSource = query2;
        GridView1.DataBind();
        TextBox3.Text = "";

    }

    protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)
    {
        DetailsView1.PageIndex = GridView1.SelectedIndex;
    }
    protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        DetailsView1.PageIndex = GridView1.SelectedIndex;
    }

    
   
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.EditIndex = -1;
        GridView1.SelectedIndex = -1;
    }


   




}

Open in new window


Please advice how can it be done.

Many thanks
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE