C# ASP.NET Repeater-如何在按钮提交时刷新数据
我看到了类似的帖子,但有些不清楚 这是中继器头:C# ASP.NET Repeater-如何在按钮提交时刷新数据,c#,asp.net,datarepeater,C#,Asp.net,Datarepeater,我看到了类似的帖子,但有些不清楚 这是中继器头: <asp:Repeater ID="rptGetAll" OnItemCommand="Buttons_OnItemCommand" runat="server" OnLoad="rptGetAll_Load"> 但当页面完成时,数据不会更新。我错过了什么 更新: 这是中继器负载: protected void rptGetAll_Load(object sender, EventArgs e) { DataTable d
<asp:Repeater ID="rptGetAll" OnItemCommand="Buttons_OnItemCommand" runat="server" OnLoad="rptGetAll_Load">
但当页面完成时,数据不会更新。我错过了什么
更新:
这是中继器负载:
protected void rptGetAll_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand("administratorGetAll", con))
{
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
da.Fill(dt);
}
}
}
rptGetAll.DataSource = dt;
rptGetAll.DataBind();
}
在像这样添加参数值时,请尝试不同的方法
cmd.Parameters.Add("@originalID", SqlDbType.VarChar);
cmd.Parameters["@originalID"].Value = hfID.Value;
您将中继器与先前填充的数据表dt绑定。用最新数据重新填充数据表,并在单击保存按钮时将其绑定到repeater。您可以发布rptGetAll\u Load and Submit\u click中的代码吗?在进行数据绑定之前,您要将数据源设置为什么?@Abe我添加了OnLoad事件和onclick这并不是onclick的全部内容,是吗?我遗漏了一些毫无意义的内容。你能详细说明“数据未更新”吗?调试
rptGetAll\u Load
时,数据是否返回-是否填充了dt
?另外,您如何进行数据绑定-与DataBinder.Eval
或ItemDataBound
事件内联?我喜欢后者。我也不知道为什么中继器会有一个Load
事件。该代码(中继器的绑定)应位于按钮单击事件上。这会导致此错误:“此SqlParameterCollection中不包含带有ParameterName“@emailAddress”的SqlParameter。”当应用于其他事件时params@Bry4n是否检查了所有参数名称是否正确?
protected void rptGetAll_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand("administratorGetAll", con))
{
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
da.Fill(dt);
}
}
}
rptGetAll.DataSource = dt;
rptGetAll.DataBind();
}
cmd.Parameters.Add("@originalID", SqlDbType.VarChar);
cmd.Parameters["@originalID"].Value = hfID.Value;