2011-06-29 24 views
0

私はデータベースから動力学的に取り込まれたgridviewを持っています。いくつかのフィールドはかなり長いです。私は、セル内のテキストの長さを減らす方法を見つけました。 編集ビューに入ると、すべてのフィールがシングルラインのテキストボックスに表示されますが、テキストボックスのサイズは小さすぎます。 texboxを別のフィールドに置き換えるにはどうすればいいですか?できれ<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; 

     } 
    } 
} 

答えて

1

を試みるソリューションが見つかりました:

protected void gvData_PreRender(object sender, EventArgs e) 
{ 
    if (this.gvData.EditIndex != -1) 
    { 
     TextBox tb = new TextBox(); 

     for (int i = 0; i < gvData.Rows[gvData.EditIndex].Cells.Count; i++) 
      try 
      { 
       tb = (TextBox) 
        gvData.Rows[gvData.EditIndex].Cells[i].Controls[0]; 

       if (tb.Text.Length >= 30) 
       { 
        tb.TextMode = TextBoxMode.MultiLine; 
       } 
      } 
      catch { } 
    } 
} 
1

で次のコード

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 = e.Row.Cells[i].Controls[0] as TextBox; 
    txtBox.TextMode = TextBoxMode.MultiLine; 

     } 
    } 
} 
+0

これは動作しないでしょう。 RowDataBoundにはテキストボックスはありません。 Roweditingで作成されます。 –

関連する問題