Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I'm trying to populate a asp.net detailview control but I only want it to be displayed after a button click which will send the ID to search for the record from a textbox

Thank u in advance
Posted
Comments
Malli_S 26-Jul-12 9:29am    
So, what is the problem? What error you are getting? Can you please put your code snippet here? So that it'll help other to help you.

First you need to get the Id from text box:-
C#
int id = Convert.ToInt32(txtId.Text);

Then On button_Click :-
C#
Protected void button_Click(object sender, EventArgs e)
{
  SqlConnection con = new SqlConnection("your connection string");
  SqlCommand cmd = new SqlCommand("SELECT * FROM [table_Name] WHERE Id=@Id",con)
  cmd.Parameters.AddWithValue("@Id",id);
  //id is your value retrieved from textbox.
  SqlDataAdapter da = new SqlDataAdapter(cmd);
  DataSet ds = new DataSet();
  da.Fill(ds);
  //now bind the datasource with DetailsView Control.
  detailsView1.DataSource = ds;
  detailsView1.DataBind();
}


Hope it will help you.
Best of luck.
 
Share this answer
 
v3
I don't see why you are stuck in implementing it.

Steps:
1. Define a detailView control and set it's visibility to false in your aspx file.
2. Define a button control. On click of it get data for detailsView and then set it's Visible property to true in code behind.

Done! Try!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900