我有一个按钮点击事件。我想点击按钮时在转发器中显示数据。
如何在点击事件中使用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文件的转发器代码,其中重复代码为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>
答案 0 :(得分:0)
调用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();
}