Add Scrollbar to dynamic Panel using C# and VB.Net in ASP.Net

Last Reply 27 days ago By pandeyism

Posted 27 days ago

how to add slim scroll-bar on dynamic panel                

Panel Pnlcomment = new Panel();
Pnlcomment.ID = "Pnlcomment" + i.ToString();
Pnlcomment.CssClass = "panel panel-default";
Pnlcomment.Visible = true
Pnlcomment.Style.Add("overflow-y", "auto");
//Pnlcomment.Style.Add("overflow-x", "hidden");
//Pnlcomment.Style.Add("overflow-y-width", "3px");
Pnlcomment.Style.Add("border-radius", "12px");
Pnlcomment.Style.Add(" border", "3px solid #fff");
Pnlcomment.Style.Add("background-color", "white");

 

You are viewing reply posted by: pandeyism 27 days ago.
Posted 27 days ago

Hi IamAzhar,

Refer below sample.

HTML

<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false">
    <Columns>
        <asp:BoundField DataField="Name" HeaderText="Name" />
        <asp:BoundField DataField="Status" HeaderText="Status" />
    </Columns>
</asp:GridView>

Namespaces

C#

using System.Data;

VB.Net

Imports System.Data

Code

C#

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            Panel Pnlcomment = new Panel();
            Pnlcomment.ID = "Pnlcomment";
            Pnlcomment.Style.Add("overflow", "scroll");
            Pnlcomment.Style.Add("overflow-x", "hidden");
            Pnlcomment.Style.Add("border-radius", "12px");
            Pnlcomment.Style.Add(" border", "3px solid #fff");
            Pnlcomment.Style.Add("max-height", "200px");
            Pnlcomment.Style.Add("width", "150px");
            Pnlcomment.Style.Add("background-color", "white");
            DataTable dt = new DataTable();
            dt = new DataTable();
            dt.Columns.AddRange(new DataColumn[2] { new DataColumn("Name"), new DataColumn("Status") });
            dt.Rows.Add("John", "Pending");
            dt.Rows.Add("Rick", "Complete");
            dt.Rows.Add("Andrew", "Complete");
            dt.Rows.Add("Peter", "Pending");
            dt.Rows.Add("Mudassar", "Complete");
            dt.Rows.Add("John", "Pending");
            dt.Rows.Add("Rick", "Complete");
            dt.Rows.Add("Andrew", "Complete");
            dt.Rows.Add("Peter", "Pending");
            dt.Rows.Add("Mudassar", "Complete");
            dt.Rows.Add("John", "Pending");
            dt.Rows.Add("Rick", "Complete");
            dt.Rows.Add("Andrew", "Complete");
            dt.Rows.Add("Peter", "Pending");
            dt.Rows.Add("Mudassar", "Complete");
            this.gvCustomers.DataSource = dt;
            this.gvCustomers.DataBind();
            Pnlcomment.Controls.Add(gvCustomers);
            form1.Controls.Add(Pnlcomment);
        }
    }

VB.Net

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    If Not Me.IsPostBack Then
        Dim Pnlcomment As Panel = New Panel()
        Pnlcomment.ID = "Pnlcomment"
        Pnlcomment.Style.Add("overflow", "scroll")
        Pnlcomment.Style.Add("overflow-x", "hidden")
        Pnlcomment.Style.Add("border-radius", "12px")
        Pnlcomment.Style.Add(" border", "3px solid #fff")
        Pnlcomment.Style.Add("max-height", "200px")
        Pnlcomment.Style.Add("width", "150px")
        Pnlcomment.Style.Add("background-color", "white")
        Dim dt As DataTable = New DataTable()
        dt = New DataTable()
        dt.Columns.AddRange(New DataColumn(1) {New DataColumn("Name"), New DataColumn("Status")})
        dt.Rows.Add("John", "Pending")
        dt.Rows.Add("Rick", "Complete")
        dt.Rows.Add("Andrew", "Complete")
        dt.Rows.Add("Peter", "Pending")
        dt.Rows.Add("Mudassar", "Complete")
        dt.Rows.Add("John", "Pending")
        dt.Rows.Add("Rick", "Complete")
        dt.Rows.Add("Andrew", "Complete")
        dt.Rows.Add("Peter", "Pending")
        dt.Rows.Add("Mudassar", "Complete")
        dt.Rows.Add("John", "Pending")
        dt.Rows.Add("Rick", "Complete")
        dt.Rows.Add("Andrew", "Complete")
        dt.Rows.Add("Peter", "Pending")
        dt.Rows.Add("Mudassar", "Complete")
        Me.gvCustomers.DataSource = dt
        Me.gvCustomers.DataBind()
        Pnlcomment.Controls.Add(gvCustomers)
        form1.Controls.Add(Pnlcomment)
    End If
End Sub

Screenshot