如何在没有任何数据库连接的情况下将数据内容添加到同一页中的数据网格

本文关键字:数据 添加 网格 数据网 一页 任何 情况下 数据库连接 | 更新日期: 2023-09-27 18:33:03

说,我有一个文本框 - 当用户在文本框中输入内容并单击添加时,内容应该在没有任何数据库连接的情况下填充在数据网格中。 用户可以在文本框中添加重复的项目,然后单击"添加",以便每个值都填充在网格中。我如何实现这一点?

如何在没有任何数据库连接的情况下将数据内容添加到同一页中的数据网格

你可以尝试这样的事情,首先你必须 导入System.Collection.Generic 命名空间

 private List<string> addContent(string content)
{
    //create a generic list of string type
    List<string> s = new List<string>();
    for (int i = 0; i < 10; i++)
    {
        s.Add(content);
    }
    return s;
}
protected void btnAdd_Click(object sender, EventArgs e)
{
   //Passed the List<> as DataSource and then bind the content in the list<> in the  DataGrid
    this.DataGrid1.DataSource = this.addContent(this.txtadd.Text);
    this.DataGrid1.DataBind();
}

我希望这对你有用