views:

37

answers:

1

Everything is ok. i van see StyleSheet.css in page source.But css effect can not run my gridview. How can i do that

 public class MyGridView : WebPart
    {
        GridView gvCustomers;

        protected override void CreateChildControls()
        {
            gvCustomers = new GridView();
            HtmlHead head = (HtmlHead)Page.Header;
            HtmlLink link = new HtmlLink();
            link.Attributes.Add("href", Page.ResolveClientUrl("StyleSheet.css"));
            link.Attributes.Add("type", "text/css");
            link.Attributes.Add("rel", "stylesheet");
            head.Controls.Add(link);

            gvCustomers.CssClass = "tablestyle";
            gvCustomers.HeaderStyle.CssClass = "headerstyle";
            gvCustomers.AlternatingRowStyle.CssClass = "altrowstyle";
            gvCustomers.RowStyle.CssClass = "rowstyle";
            this.Controls.Add(gvCustomers);
        }

        public object DataSource
        {
            get {
                this.EnsureChildControls();
                return gvCustomers.DataSource; }
            set {
                this.EnsureChildControls();

                gvCustomers.DataSource = value; }
        }
A: 

Have you tried a ScriptManagerProxy control? using this control within your user control can determine if the CSS has already been added to your page, and only add one reference to your css file

N8
how can i use it?
Phsika
sorry for the late response: <asp:ScriptManagerProxy ID="smpScriptAdder" runat="server"> <Scripts> <asp:ScriptReference Path="~/Javascript/MyResource.css" /> </Scripts> </asp:ScriptManagerProxy>
N8