下面是我希望控件工作的方式。点击gridview中的一行编辑。在其中一列中有一个文本框,我希望它是空白的,即使该列的数据库中有数据,但是当我单击更新时,我想要用户输入的任何新文本来更新该列的数据库。这将是单向数据绑定,但反过来呢?ASP .Net Gridview仅在点击更新时绑定到数据
0
A
回答
0
下面是我如何在生成的select,update和delete方法中使用sql数据源。
首先,你需要做的是要与一个项目模板,并编辑项目模板编辑这样的一个模板场任意列:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="ID" DataSourceID="SqlDataSource1"
onrowupdating="GridView1_RowUpdating">
<Columns>
<asp:TemplateField HeaderText="City" SortExpression="City">
<ItemTemplate>
<asp:Label runat="server" Text='<%# Eval("City") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtCityEdit" Text=""></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
下一页处理GridView控件的更新事件的:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//find the value control who's value you want
TextBox tb = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtCityEdit");
//since we are not using a bound column for city we need to explicitly insert the value
//into the update parameter.
SqlDataSource1.UpdateParameters["City"].DefaultValue = tb.Text;
}
即使您使用的不是SQL数据源,也应该是基本的解决方案。
0
// Find notes textbox
TextBox tb = (TextBox)MyActiveReferrals.Rows[e.RowIndex].FindControl("NotesTextBox");
e.NewValues.Add("Notes", tb.Text);
我用了一个linq数据源。
相关问题
- 1. 单向数据绑定gridview - 仅更新?
- 2. 如何绑定IQueryable数据到asp gridview
- 3. 在数据库更改时更新ASP.NET数据绑定GridView
- 4. 排序后数据绑定更新gridview
- 5. ASP.Net的GridView重新绑定不上的按钮,点击数据
- 6. 用新的数据绑定刷新gridview
- 7. 在点击时显示gridview数据
- 8. 在Treeview节点上绑定Gridview点击
- 9. 绑定列表到GridView在ASP .Net C#MVC Jquery
- 10. 可可绑定仅在窗口焦点更改时更新
- 11. ASP .net MVC Jqgrid数据绑定
- 12. ASP gridview不更新数据库
- 13. .Net EntityFramework绑定到gridview
- 14. GridView重新绑定新参数数据
- 15. 将数据绑定到gridview时出错
- 16. 绑定数据到GridView
- 17. 数据绑定到GRIDVIEW
- 18. 数据绑定在使用{绑定}或{绑定}时未更新
- 19. 更新重定向ASP .net
- 20. HTML5如何本地数据库绑定到ASP GridView的
- 21. 将数据绑定到gridview不显示网格asp
- 22. 转到特定页面按钮点击在asp gridview
- 23. ASP .NET - 如何刷新数据绑定DataList?
- 24. jquery更新数据点击将绑定两次
- 25. asp GridView没有绑定
- 26. 修改Asp gridview绑定域
- 27. Gridview数据绑定
- 28. 将gridview格式化的数据绑定到新的gridview中
- 29. 基于按钮点击的Gridview数据绑定
- 30. 在调用数据绑定后Gridview没有更新
这并不适合我,但绝对让我走上正轨!我最大的问题是将文本框的值从模板字段中取出,因为intellisense不会给我。 我尝试使用UpdateParameters喜欢你的例子,但得到一个空引用错误,然后我试图添加我的新集合,并没有工作。 我结束了我的新值添加到“NewValues”集合,它的工作。 – user204019