tags:

views:

38

answers:

2

I need to load the database values into the grid view by checking the attribute "id".

If the id value which I entered is equal to database, then it'll load in the grid view.

Help me to do that

A: 

Hey,

You have to loop through the records on the backend and parse out the records you don't want to show before you bind to the gridview; it's much easier that way.

HTH.

Brian
This is my code:DataSet ds = new DataSet(); string str = "select *from Personal where id='" + TextBox1.Text + "'"; SqlDataAdapter da = new SqlDataAdapter(str, con); da.Fill(ds, "Personal"); GridView1.DataSource = ds.Tables["Personal"].DefaultView; GridView1.DataBind();
Sivakumar
OK, and what is not working with the code you have given me, or what do you need assistance with?
Brian
While click on the button it doesn't show any grid
Sivakumar
OK, as long as the query is correct, there isn't anything fundamentally wrong with the code, verify the following items: 1) use debugging to take the query stored in str at runtime, and run it in the SQL mgmt studio to see that it returns any results. 2) try binding to the table directly, rather than the default view. 3) also when debugging mouseover the table and see if it has rows. 4) then check the UI; temporarily allow autogeneratecolumns="true" to see if you see anything.
Brian
A: 

You might want to try to add this to the code-behind module

void Page_load(object sender, EventArgs e)      
{                                   
  if (!Page.IsPostBack)
  {
     CreateGrid();          
  }     
}

void CreateGrid()
{
  DataSet ds = new DataSet(); 
  string str = "select * from Personal where id='" + TextBox1.Text + "'"; 

  SqlDataAdapter da = new SqlDataAdapter(str, con); 

  da.Fill(ds, "Personal"); 

  GridView1.DataSource = ds.Tables["Personal"].DefaultView; 
  GridView1.DataBind(); 
}
Lost in Alabama