后面的代码,但要填充detailview asp.net控件 [英] code behind but to populate detailview asp.net control

查看:90
本文介绍了后面的代码,但要填充detailview asp.net控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试填充asp.net detailview控件,但我只希望在单击按钮后显示该控件,该控件将发送ID以便从文本框中搜索记录

预先感谢您

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

推荐答案

首先,您需要从文本框中获取ID:-
First you need to get the Id from text box:-
int id = Convert.ToInt32(txtId.Text);


然后在button_Click上:-


Then On button_Click :-

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.


我不明白您为什么坚持执行它.

步骤:
1.在aspx文件中定义一个detailView控件并将其可见性设置为false.
2.定义一个按钮控件.单击它,获取detailsView的数据,然后在后面的代码中将其Visible属性设置为true.

完毕!试试吧!
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!


这篇关于后面的代码,但要填充detailview asp.net控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆