当按钮单击ASP时,如何中继器显示数据



我有一个按钮点击事件。单击按钮时,我想在中继器中显示数据。如何在单击事件中使用bindRepeaterData

 protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        BindRepeaterData();
    }
}

protected void clickme(object sender, EventArgs e)
{
     protected void BindRepeaterData( )
    {
      con.Open();
      SqlCommand cmd = new SqlCommand("select question from question where tag='asp'", con);
      int count = (int)cmd.ExecuteScalar();
      DataSet ds = new DataSet();
      SqlDataAdapter da = new SqlDataAdapter(cmd);
      da.Fill(ds);
     RepDetails.DataSource = ds;
     RepDetails.DataBind();
     con.Close();
    }
}

来自.aspx文件的中继器代码,其中repter代码为repdetails

 <div >
    <asp:Repeater  runat="server" ID="RepDetails"  >
        <ItemTemplate>
            <table class="op">
            <thead>
            <tr> 
               <td>
                   <asp:Label runat="server" ID="question" Text=' <%#("question") %>' ></asp:Label>
               </td> 
            </tr>
            </thead>
        </table>
        </ItemTemplate>
        </asp:Repeater>
</div>           

呼叫bindrepeaterdata();在按钮单击事件中。

  protected void BindRepeaterData( )
{
  con.Open();
  SqlCommand cmd = new SqlCommand("select question from question where tag='asp'", con);
  int count = (int)cmd.ExecuteScalar();
  DataSet ds = new DataSet();
  SqlDataAdapter da = new SqlDataAdapter(cmd);
  da.Fill(ds);
  RepDetails.DataSource = ds;
  RepDetails.DataBind();
  con.Close();
}
protected void clickme(object sender, EventArgs e)
{
 BindRepeaterData();
}

最新更新