将CSS样式应用于gridview对象 [英] apply css style to gridview object
本文介绍了将CSS样式应用于gridview对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在研究导出Excel功能.我在其中将数据表分配给gridview对象并呈现该控件
Hi,
I am working on export excel functionality. In which I am assigning datatable to gridview object and rendering that control
System.Web.UI.WebControls.GridView dgv = new System.Web.UI.WebControls.GridView();
DataTable dtobj = assmnt.OutstandingActionRPT(compprop);
if (dtobj.Rows.Count > 0)
{
try
{
dtobj.Columns.Remove("QuestionID");
dtobj.Columns.Remove("UserID");
dtobj.Columns.Remove("DID");
dtobj.Columns.Remove("AreaofConcern");
dtobj.Columns[0].ColumnName = "Statement";
dtobj.Columns[1].ColumnName = "Department";
dtobj.Columns[2].ColumnName = "Name";
//dtobj.Columns[2].ColumnName = "";
}
catch (Exception)
{
}
dgv.BorderWidth = 0;
//dgv.HeaderStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Left;
dgv.DataSource = dtobj;
dgv.DataBind();
}
}
Response.ContentType = "application/x-msexcel";
Response.AddHeader("Content-Disposition", "attachment; filename=ExcelFile.xls"); Response.ContentEncoding = System.Text.Encoding.UTF8;
StringWriter tw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(tw);
dgv.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
我必须增加第一列的宽度,并向左分配标头的水平对齐.
但是我没有解决办法
请让我知道执行此操作的方法.
谢谢
I have to increase the width of first column as well as assign horizontal allign of header to left.
BUT I am not getting solution
Please let me know the way to do this.
Thanks
推荐答案
我提供了一个链接,希望对您有帮助
在CSS.NET GridView中应用CSS [ ^ ]
现在,我为您提供一个有关如何在Grid中应用CSS的简单示例
i am giving a link i hope it will help you
Applying CSS in ASP.NET GridView[^]
now i give you one simple example for How to apply CSS in Grid
<style type="text/css">
.categories h1
{
font:bold 16px Arial, Sans-Serif;
}
.movies
{
margin-left:20px;
margin-bottom:10px;
width:100%;
}
</style>
<asp:GridView
id="grdMovies"
CssClass="categories"
Runat="server">
<Columns>
<asp:TemplateField>
<ItemStyle Width="7%" BorderColor="Dodgerblue" BackColor="white"/>
<ControlStyle Width="96%" />
<ItemTemplate>
<asp:Label ID="lblQId" Font-Size="8pt" Font-Names="Verdana" runat="server" Text='<%# Bind("QuestionID") %>' style="border: none 0px; text-align:left"/>
</ItemTemplate>
</asp:TemplateField>
<Columns>
</asp:GridView>
我认为这个例子可以解决您的问题
i think this example will solve your problem
这篇关于将CSS样式应用于gridview对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文