Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
when i put one query in textbox and click button then how to show their query output in grid view or repeater or data list in same page asp.net c#


my code

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
getquery();
}
}
protected void btn_query_Click(object sender, EventArgs e)
{
con = new SqlConnection(strcon);
con.Open();
SqlCommand cmd = new SqlCommand("sp_query", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@query_name",txt_query_name.Text);
cmd.Parameters.AddWithValue("@queries",txt_query.Text);
cmd.ExecuteNonQuery();
con.Close();
getdata();
getquery();

}
void getquery()
{
con = new SqlConnection(strcon);
con.Open();
string query = txt_query.Text;
SqlCommand cmd = new SqlCommand("sp_query_select", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@condition", txt_query.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da = new SqlDataAdapter(cmd);
da.Fill(dt);

if (dt.Rows.Count > 0)
{
query_repeat.DataSource = dt;
query_repeat.DataBind();
}
else
{
query_repeat.DataSource = null;
query_repeat.DataBind();
}
}
protected void query_repeat_ItemCommand(object source, RepeaterCommandEventArgs e)
{
getquery();
}
Posted
Comments
Sinisa Hajnal 6-Feb-15 7:38am    
So...your query always has the same structure or you have to divine it somehow? You're setting datasource to query_repeat, what is the problem? Please describe your problem in more details, offer sample data and describe the behaviour you're getting as opposed to what you're expecting. Thank you.
Member 10918596 6-Feb-15 7:47am    
when i put one query in textbox and click button then how to show their output via grid view or repeater or data list in asp.net
Sinisa Hajnal 6-Feb-15 7:50am    
You didn't answer any of the question I asked. You just repeated your question. You're setting datasource to query_repeat. Is that your repeater? Please check my last post and answer all questions as best as you can.
Member 10918596 6-Feb-15 7:57am    
i expect how to pass values to repeater
Member 10918596 6-Feb-15 8:00am    
whatever query i enter in text box,and click to submit then it generates output directly to repeater with out connect any like using eval in repeater for item template.just i enter query in textbox directly o/p bind to repeater or grid view

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