Hi @Donald Symmons,
Page.Header.Controls.Add needs to be used in the Page_Load method. I think you can try to complete all the requirements in Page_Load.
You can use BackColor to set Gridview color.
Demo
protected void Page_Load(object sender, EventArgs e)
{
string constr = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd1 = new SqlCommand("SELECT * FROM DesignTable WHERE Id = @Id", con);
cmd1.Parameters.AddWithValue("@Id", Session["user"]);
con.Open();
SqlDataReader dr = cmd1.ExecuteReader();
if (dr.Read())
{
string Colorlbl = dr[1].ToString();
Color color = Color.FromName(Colorlbl);
MyGrid.BackColor = color;
string LabelFont = dr[2].ToString();
Page.Header.Controls.Add(new System.Web.UI.LiteralControl("<link rel=\"stylesheet\" type=\"text/css\" href=\" https://fonts.googleapis.com/css?family=" + LabelFont + "\" />"));
MyGrid.Attributes["style"] = "font-family: \'" + LabelFont + "\';";
}
con.Close();
if (!this.IsPostBack)
{
SqlCommand cmd = new SqlCommand("SELECT CustomerId, Name FROM Customers");
SqlDataAdapter sda = new SqlDataAdapter();
cmd.Connection = con;
sda.SelectCommand = cmd;
DataTable dt = new DataTable();
sda.Fill(dt);
MyGrid.DataSource = dt;
MyGrid.DataBind();
}
}
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.