0
我有一個從數據庫動態填充的gridview。一些領域相當長。我找到了一種方法來減少單元格中文本的長度。 現在,當我處於編輯視圖中時,所有字符都在單行文本框中,對於文本數量而言太小。我怎樣才能替換一個texbox與另一個領域? Preferrably與<textarea></textarea>
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;
}
}
}
這是行不通的。 RowDataBound上沒有文本框。它在Rowediting上創建。 –