Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.NET Repeater-如何在按钮提交时刷新数据_C#_Asp.net_Datarepeater - Fatal编程技术网

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;