[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 708
  • Last Modified:

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.
0
rgh119
Asked:
rgh119
  • 2
1 Solution
 
GreymanMSCCommented:
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now