简体   繁体   中英

How do we add border to a datagrid?

I have a datagrid which displays data read from an xml file.

DataSet ds = new DataSet();
            ds.ReadXml(Server.MapPath(@"App_Data\Mediaplan.xml"));
            DataView dv = ds.Tables[1].DefaultView;
            dv.RowFilter = "ActivityId=" + DropDownList1.SelectedValue;
            dg.DataSource = dv;
            dg.DataBind();
            PlaceHolder1.Controls.Add(dg); 

     }

My doubt is how do I add a border to this datagrid? I need a simple black border around the grid. If it can only be done in HTML side, plz let me know how. I am a new bee to .NET. I am building an ASP.net web app using VS 2010.

Thanks in advance, Pooja

You can add the border to datagrid by providing the BorderColor, BorderWidth attributes to the Datagrid.

Here is the example......

<asp:DataGrid ID="dg1" runat="server" BorderColor="Black" BorderWidth="2px" 
            CellPadding="0">

      </asp:DataGrid>

If you are defining in code behind then try this adding in code behind.

dg1.BorderWidth = Unit.Pixel(2);
dg1.BorderColor = System.Drawing.Color.Black;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM