DetailsView Field Scroll Bar

Is it possible to have one fo the fields in a DetailsView scroll when the data is too large to display.  i am currently using all "databound" fields.  I have a summary field that I would like to remain approximately 3-5 lines in hieght and a scroll bar appears when the data returned is larger than that amount of lines.
rgh119Asked:
Who is Participating?
 
GreymanMSCConnect With a Mentor Commented:
Convert your summary field into a TemplateField, then use MultiLine TextBox controls to hold the data in all modes.
<asp:TemplateField HeaderText="Data Field">
    <EditItemTemplate>
        <asp:TextBox ID="txtDataField" runat="server" 
            Text='<%# Bind("DataField") %>' 
            TextMode="Multiline" Rows="5" Columns="30"
        ></asp:TextBox>
    </EditItemTemplate>
    <InsertItemTemplate>
        <asp:TextBox ID="txtDataField" runat="server" 
            Text='<%# Bind("DataField") %>' 
            TextMode="Multiline" Rows="5" Columns="30"
        ></asp:TextBox>
    </InsertItemTemplate>
    <ItemTemplate>
        <asp:TextBox ID="txtDataField" runat="server" 
            ReadOnly="True" Text='<%# Bind("DataField") %>'
            TextMode="Multiline" Rows="5" Columns="30"
         ></asp:TextBox>
    </ItemTemplate>
</asp:TemplateField>

Open in new window

0
 
GreymanMSCCommented:
That will be a fixed height textbox.  To allow it to shrink if less than 5 rows, use the DetaiView's DataBound event.
    Protected Sub TheDetailsView_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles TheDetailsView.DataBound
        Dim T As TextBox = CType(sender, DetailsView).FindControl("txtDataField")
        If Not T Is Nothing Then
            Dim X As Integer = T.Text.Length \ T.Columns
            If X < 3 Then
                T.TextMode = TextBoxMode.SingleLine
                T.Height = New Unit(42, UnitType.Pixel)
            ElseIf X < 5 Then
                T.TextMode = TextBoxMode.SingleLine
                T.Height = New Unit((X + 1) * 14, UnitType.Pixel)
            Else
                T.TextMode = TextBoxMode.MultiLine
                T.Height = Nothing
                T.Rows = 5
            End If
        End If
    End Sub

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.