I have a gridview which I used to display tabular data. I want the users to edit the field values and save it. Is there any way to add a textbox in place of bound field. This is my gridview.
我有一个gridview,我用它来显示表格数据。我希望用户编辑字段值并保存。有没有办法添加文本框来代替绑定字段。这是我的gridview。
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
Height="186px" Width="325px">
<Columns>
</Columns>
</asp:GridView>
This is the code behind which populate the GridView
这是填充GridView的代码
public List<DataControlField> columns = new List<DataControlField>();
public object DataSource { get; set; }
protected void Page_Init(object sender, EventArgs e)
{
for (int i = 0; i < 10; i++)
{
BoundField bf = new BoundField() ;
bf.HeaderText = "LastName" ;
bf.DataField = "LastName";
columns.Add(bf);
}
foreach (DataControlField col in columns)
{
GridView1.Columns.Add(col);
}
}
protected void Page_Load(object sender, EventArgs e)
{
List<Data> lastN = new List<Data>() ;
for(int i = 0 ; i < 50; i++ )
{
lastN.Add(new Data(i.ToString()));
}
GridView1.DataSource = lastN;
GridView1.DataBind();
}
}
2 个解决方案
#1
I would like to suggest you to try listview, it allows you to edit the dynamic data, such as the content in textbox
我建议您尝试使用listview,它允许您编辑动态数据,例如文本框中的内容
#2
You can use a GridView with EditTemplates. You can refer to this example for that.
您可以将GridView与EditTemplates一起使用。你可以参考这个例子。
It is possible to edit all rows of a GridView at the same time. Refer to this example.
可以同时编辑GridView的所有行。请参阅此示例。
You can optionally use Telerik's ASP.NET Data Grid that you can configure to work like excel using this example.
您可以选择使用Telerik的ASP.NET数据网格,您可以使用此示例将其配置为像excel一样工作。
#1
I would like to suggest you to try listview, it allows you to edit the dynamic data, such as the content in textbox
我建议您尝试使用listview,它允许您编辑动态数据,例如文本框中的内容
#2
You can use a GridView with EditTemplates. You can refer to this example for that.
您可以将GridView与EditTemplates一起使用。你可以参考这个例子。
It is possible to edit all rows of a GridView at the same time. Refer to this example.
可以同时编辑GridView的所有行。请参阅此示例。
You can optionally use Telerik's ASP.NET Data Grid that you can configure to work like excel using this example.
您可以选择使用Telerik的ASP.NET数据网格,您可以使用此示例将其配置为像excel一样工作。