1

One of BoundField in my GridView has a very long string without space. I want to dispaly it correctly. According to the similar question. I used the code

<asp:TemplateField HeaderText="ICD9" ItemStyle-Width="75px" SortExpression="ICD9" >
                        <ItemTemplate>
                            <div style="width: 75px; overflow: hidden; white-space: nowrap; word-wrap: break-word;">
                                <%# Eval("ICD9")%>
                                </div>
                        </ItemTemplate>
                    </asp:TemplateField>

Although it works, but when I switch it the Edit mode. The column can not be editted.The textbox doesn't show up.

Thanks. image

Please look at the second column, it may has a long string.(Right now it is "None"). It can not be editted.

Community
  • 1
  • 1
  • 1
    You've showed the `ItemTemplate` but your issue is in the [EditItemTemplate](http://msdn.microsoft.com/en-us/library/ms972948.aspx), isn't it? – Tim Schmelter Apr 10 '12 at 15:33
  • But why other columns can be editted? They don't have EditTemplate. I use stored procedures. –  Apr 10 '12 at 15:39

1 Answers1

0

Inside your <TemplateField>, you also need an <EditItemTemplate>:

<asp:TemplateField HeaderText="ICD9" ItemStyle-Width="75px" SortExpression="ICD9" >
    <ItemTemplate>
        <div style="width: 75px; overflow: hidden; white-space: nowrap; word-wrap: break-word;">
            <%# Eval("ICD9")%>
        </div>
    </ItemTemplate>
    <EditItemTemplate>
        <div style="width: 75px; overflow: hidden; white-space: nowrap; word-wrap: break-word;">
            <asp:TextBox ID="TextBox1" runat="server"
            Text='<%# Bind("ICD9") %>'></asp:TextBox>
        </div>
    </EditItemTemplate>
</asp:TemplateField>

This way, when your GridView goes into edit mode, it knows what to render for that field.

Without being able to see your other fields, it's possible they are working because they are simply <BoundField>s, which would have this behavior by default (when in the TemplateField, you have to explicitly define the edit and non-edit modes).

You can take a look at this (sort of old) tutorial for more information on TemplateFields: Using TemplateFields in the GridView control

Josh Darnell
  • 11,304
  • 9
  • 38
  • 66
  • @Love Hmmm, you might have to set `TextMode="MultiLine"` on that TextBox to get it to wrap. You'd then somehow have to set the height dynamically, but hopefully that gets you started. Let me know if that works for you. – Josh Darnell Apr 10 '12 at 16:13