【发布时间】:2012-03-22 07:05:09
【问题描述】:
我在网格视图中有一个边界域。如何将绑定字段更改为仅针对特定列的文本框?
我试过了
BoundField colname= new BoundField();
grid.Columns.Add(colname as TextBox);
但它有一个演员表
【问题讨论】:
标签: asp.net
我在网格视图中有一个边界域。如何将绑定字段更改为仅针对特定列的文本框?
我试过了
BoundField colname= new BoundField();
grid.Columns.Add(colname as TextBox);
但它有一个演员表
【问题讨论】:
标签: asp.net
我不确定这是否适合您的情况,但您可以尝试使用模板字段,如下所示:
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#Eval("SomeValue")%>' ... />
</ItemTemplate>
</asp:TemplateField>
编辑:从后面的代码将文本框添加到项目模板:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
TemplateField txtColumn = new TemplateField();
txtColumn.ItemTemplate = new TextColumn();
GridView1.Columns.Add(txtColumn);
}
}
public class TextColumn : ITemplate
{
public void InstantiateIn(System.Web.UI.Control container)
{
TextBox txt = new TextBox();
txt.ID = "MyTextBox";
container.Controls.Add(txt);
}
}
EDIT:设置动态添加的TextBox的文本
//get the cell and clear any existing controls
TableCell cell = e.Row.Cells[0];
cell.Controls.Clear();
//create a textbox and add it to the cell
TextBox txt = new TextBox();
txt.Text = cell.Text;
cell.Controls.Add(txt);
【讨论】: