如何将数据绑定到Datagrid视图中的文本框中 [英] How can i bind data into textboxes, inside the Datagrid View
本文介绍了如何将数据绑定到Datagrid视图中的文本框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是asp.net开发人员,我刚接触到这个..
我有asp.net GridView,我添加了一些文本框字段,所以我想要绑定数据到这个文本框是吗可能在asp.net?
I am asp.net developer and im newly to this..
I have asp.net GridView and I added some text box fields to that,so i want bind data into this textboxes is it possible in asp.net?
推荐答案
<asp:TextBox ID="txtValue" runat="server" Text='<%# Bind("Value") %>'></asp:TextBox>
这里 Value
name是 DataSource $ c中的列名 $ c>。
假设您从数据库获取数据并将其绑定到 DataSet
。
所以,这个 Value
列应该出现在 DataSet $ c $里面c>。
Here "Value
" name is the Column Name in the DataSource
.
Suppose, you are getting data from Database and Binding it to a DataSet
.
So, this "Value
" Column should be present inside the DataSet
.
你好,
绑定DataGridView中的单元格
到文本框,我们可以使用TextBox.DataBinding.Add()
方法使用以下代码。这里Text
表示要绑定的控件属性的名称,dt是对象表示数据源,两个
是要绑定到的属性或列表(此处为列名称)。
Hello,
To bind a cell inDataGridView
to a Text Box, we could just use the following codes, usingTextBox.DataBinding.Add()
method. And here "Text
" means the name of control property to bind, dt is the object represents the data source, and "Two
" is the property or list to bind to (column name here).
DataTable dt = new DataTable();
dt.Columns.Add("One");
dt.Columns.Add("Two");
dt.Columns.Add("Three");
dt.Rows.Add(new string[] { "1", "2", "3" });
dt.Rows.Add(new string[] { "4", "5", "6" });
dt.Rows.Add(new string[] { "7", "8", "9" });
dataGridView1.DataSource = dt;
textBox1.DataBindings.Add("Text", dt, "Two");
查看一些演示项目,链接如下所示
GridView控件
< a href =http://www.codeproject.com/Articles/37207/Editable-Gridview-with-Textbox-CheckBox-Radio-Butt> 带文本框,复选框,单选按钮和DropDown列表的可编辑网格视图大>
See some demo projects, Links are following below
GridView Control
Editable Gridview with Textbox, CheckBox, Radio Button and DropDown List
这篇关于如何将数据绑定到Datagrid视图中的文本框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文