0

I have a query which return rows with specific fields

SELECT First_Name, Midle_Name, Last_Name, Phone_home, Cell_home, ZipCode_Work, Phone_Work, Cell_Work FROM contact_info WHERE (Last_Name = @Last_Name)

and here is my code to bind this query to datagridview control.

protected void btnSearch_Click(object sender, EventArgs e) { DSSearchTableAdapters.contact_infoTableAdapter LastNameViewAdapter = new DSSearchTableAdapters.contact_infoTableAdapter(); DSSearch.contact_infoDataTable GetByLastName = LastNameViewAdapter.GetDataByLastNameView(txtSearch.Text); GridView1.DataSource = GetByLastName; GridView1.DataBind();

}

the problem that the datagridview will show all the fields in the table not the field I selected.

I'm suing VS 2008,asp.net with C# with mysql Database.

Can you help?

2 Answers 2

1

Set AutoGenerateColumns to false and define the columns explicitly for the DataGridView object.

GridView1.Columns.Add(new System.Windows.Forms.DataGridViewColumn
 {
  HeaderText = "Column Header", 
  DataPropertyName = "ColumnName"
 });
Sign up to request clarification or add additional context in comments.

1 Comment

I'm getting this error : Error 5 The type or namespace name 'DataGridViewColumn' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Ali\Documents\Visual Studio 2008\Projects\Imam_Contacts\Imam_Contacts\SearchPage.aspx.cs 45 39 Imam_Contacts
0

In the design view of an aspx page, the grid view will have an image of a '<' in the upper right hand corner of the gridview, which is called a smart tag.
alt text http://www.freeimagehosting.net/uploads/5dd1c59fe9.jpg Click on that and it will give you a menu.

From the menu select edit columns. That will bring up a Fields dialogue box. alt text http://www.freeimagehosting.net/uploads/8aafd8a14a.jpg In the bottom left of the dialogue box is a list of the columns that are in the gridview. You can select any of the columns in the list and delete them by clicking the red X next to the list. You can also use the up and down arrows to arrange the order of the columns in the gridview.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.