2011-09-02 43 views
0

不给多行文本中的GridView细胞多行文字工作不

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CategoryID" 
      DataSourceID="SqlDataSource1" ShowFooter="true" AllowPaging="True" AllowSorting="True" 
      PageSize="5" OnRowDataBound="GridView1_RowDataBound"> 
      <Columns>      
       <asp:TemplateField HeaderText="CategoryID" InsertVisible="False" SortExpression="CategoryID"> 
        <ItemTemplate> 
         <asp:Label ID="lblCategoryID" runat="server" Text='<%# Bind("CategoryID") %>'></asp:Label> 
        </ItemTemplate>     
       </asp:TemplateField> 
       <asp:TemplateField HeaderText="CategoryName" SortExpression="CategoryName"> 
        <EditItemTemplate> 
         <asp:TextBox ID="txtCategoryName" runat="server" Text='<%# Bind("CategoryName") %>'></asp:TextBox> 
        </EditItemTemplate> 
        <ItemTemplate> 
         <asp:Label ID="lblCategoryName" runat="server" Text='<%# Bind("CategoryName") %>'></asp:Label> 
        </ItemTemplate> 
       </asp:TemplateField> 
       <asp:TemplateField HeaderText="Description" SortExpression="Description"> 
        <EditItemTemplate> 
         <asp:TextBox ID="txtDesc" runat="server" Text='<%# Bind("Description") %>'></asp:TextBox> 
        </EditItemTemplate> 
        <ItemTemplate> 
         <asp:Label ID="lblDesc" runat="server" Text='<%# Bind("Description") %>'></asp:Label> 
        </ItemTemplate>        
       </asp:TemplateField>    
      </Columns> 
     </asp:GridView> 

回答

3

无文本框都TextMode设置为Multiline
在要显示为textarea的文本框上将TextMode属性设置为Multiline

e.g:

<EditItemTemplate>       
    <asp:TextBox ID="txtCategoryName" Columns="50" Rows="5" runat="server" TextMode="MultiLine" Text='<%# Bind("CategoryName") %>'></asp:TextBox>      
</EditItemTemplate> 

编辑

而且使烟标,尝试添加一个ItemStyle它,就像这样:

<ItemStyle Wrap="true" Width="200" /> 
+0

希望你不要介意。我想我会在标签可见时包含一个项目样式来包装单元格。 –

+0

@James:不是问题... – Chandu

+0

我试过那个不工作。也textwrap:true ..same结果 – biplob