Gridview编辑值
我有一个从数据库动态填充的网格视图。有些字段相当长。我找到了一种方法来缩短单元格中文本的长度。 现在,当我处于编辑视图中时,所有字段都位于单行文本框中,对于文本量来说太小了。如何用另一个字段替换文本框?最好使用
<div style="overflow:auto;">
<asp:GridView ID="gvData" OnRowDataBound="gvData_RowDataBound" OnRowEditing="gvData_RowEditing" runat="server" CellPadding="4"
ForeColor="#333333" GridLines="Vertical" AllowPaging="True"
AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" DataSourceID="DS">
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
<asp:SqlDataSource ID="DS" runat="server"></asp:SqlDataSource>
</div>
protected void gvData_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
TextBox txtBox = new TextBox();
ViewState["OrigData"] = e.Row.Cells[i].Text;
if (e.Row.Cells[i].Text.Length >= 30)
{
e.Row.Cells[i].Text =
e.Row.Cells[i].Text.Substring(0, 30) + "...";
e.Row.Cells[i].ToolTip = ViewState["OrigData"].ToString();
}
e.Row.Cells[i].Wrap = false;
}
}
}
I have a gridview which is populated dynamicaly from the database. Some of the fields are pretty long. I found a way to cut the length of the text in the cell.
Now, when I am in the edit view, all the fiels are in singleline textboxes, which are too small for the amount of text. How can I replace a texbox with another field? Preferrably with <textarea></textarea>
<div style="overflow:auto;">
<asp:GridView ID="gvData" OnRowDataBound="gvData_RowDataBound" OnRowEditing="gvData_RowEditing" runat="server" CellPadding="4"
ForeColor="#333333" GridLines="Vertical" AllowPaging="True"
AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" DataSourceID="DS">
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
<asp:SqlDataSource ID="DS" runat="server"></asp:SqlDataSource>
</div>
protected void gvData_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
TextBox txtBox = new TextBox();
ViewState["OrigData"] = e.Row.Cells[i].Text;
if (e.Row.Cells[i].Text.Length >= 30)
{
e.Row.Cells[i].Text =
e.Row.Cells[i].Text.Substring(0, 30) + "...";
e.Row.Cells[i].ToolTip = ViewState["OrigData"].ToString();
}
e.Row.Cells[i].Wrap = false;
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试下面的代码
try the following code
找到了解决方案:
found a solution: