troubleshooting Question

ASP.net C#, entity, linq

Avatar of Radim88
Radim88 asked on
C#ASP.NET
7 Comments1 Solution420 ViewsLast Modified:
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
ASKER CERTIFIED SOLUTION
JuanchoVzla

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros