在现有gridview的每一行中插入文本框 [英] Insert text box in each row of an existing gridview
本文介绍了在现有gridview的每一行中插入文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的项目中,我想通过gridview在数据库中输入值.我可以从数据库中获取数据到gridview并在每一行中添加一个文本框,以便可以在相应的文本框中输入每一行的值并更新数据库.请有人可以帮助我....
In my project, I want to enter the values in database through gridview. Can I take data from database to a gridview and add a textbox to each of the row so that I can enter the value for each row in corresponding textboxes and update database.Please anybody can help me....
推荐答案
尝试这些
editable_gridview
gridview中的文本框
try these
editable_gridview
textBox in gridview
是的.在griview的rowdatabound上添加一个新控件.
在.aspx页面中,添加到gridview控件中
yes you can. add a new control on rowdatabound of the griview.
in .aspx page add in your gridview control
OnRowDataBound="gvGridView_RowDataBound"
像这样..
like this..
<asp:GridView ID="gvGridView" runat="server" AutoGenerateColumns="False" OnRowCommand="gvGridView_RowCommand" OnRowDataBound="gvGridView_RowDataBound">
并在后面的代码中(在aspx.cs页上)
and in code behind(on aspx.cs page)
protected void gvGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (DataControlRowType.DataRow == e.Row.RowType && e.Row.RowState != DataControlRowState.Edit && (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate))
{
TextBox tx = new TextBox(); //here i m adding a control.
tx.ID = "txtCheck";
tx.Attributes.Add("runat", "server");
int i = e.Row.Cells.Count;
i = i - 1;
e.Row.Cells[i].Controls.Add(tx); //textbox is added as last column of grid
}
}
您可以参考以下链接:
将新行添加到网格视图 [ ^ ]
You can refer this link:
ADDING NEW ROW TO THE GRID VIEW[^]
这篇关于在现有gridview的每一行中插入文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文