|
 |
aspx thread: Dynamically change properties for webcontrols
Message #1 by "Mikael Larsson" <mickeboy@h...> on Fri, 1 Jun 2001 17:34:31
|
|
Hi...
I have the following problem:
I have a global variable
String TableColor = "";
and want to assign the value of TableColor to BackColor
<ASP:DataGrid id="MyDataGrid" runat="server"
Width="100%"
BackColor="<%=TableColor%>
BorderColor="black"
ShowFooter="false"
CellPadding="3"
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
/>
But I canīt get it right. Is it possible? Can someone please help me?
Best regards
Mikael
Message #2 by "Alex Lowe" <alowe@s...> on Fri, 1 Jun 2001 14:14:34 -0400
|
|
Mikael,
Yes, it is possible. What makes this difficult is that the BackColor
property of the datagrid expects a value of type System.Drawing.Color (as
opposed a value of type String which is what I think most people who are new
to the framework will try). Because of this, you can still use a string
value to represent the color you want but you will also have to pass the
string value into the FromName method of the System.Drawing.Color class. For
example (notice I set the BackColor property in the code as opposed to the
BackColor property in the datagrid declaration),
------------------- test.aspx -------------------------
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQL" %>
<script language="C#" runat="server">
String TableColor = "blue";
void Page_Load(Object Src, EventArgs e)
{
DataSet myDataSet = new DataSet();
String SelectCommand ="Select * from Products";
SQLConnection MyConnection = new SQLConnection("Data
Source=localhost; uid=sa; pwd=; Initial Catalog=northwind");
SQLDataSetCommand MyCommand = new SQLDataSetCommand(SelectCommand,
MyConnection);
MyCommand.FillDataSet(myDataSet, "Products");
DataView myDataView = myDataSet.Tables["Products"].DefaultView;
MyDataGrid.BackColor = System.Drawing.Color.FromName(TableColor);
MyDataGrid.DataSource = myDataView;
MyDataGrid.DataBind();
}
</script>
<ASP:DataGrid id="MyDataGrid" runat="server"
Width="100%"
BorderColor="black"
ShowFooter="false"
CellPadding="3"
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
/>
----------------- end of test.aspx ------------------------------
hth,
Alex
http://www.asp-grandrapids.net
webmaster@a...
---- Original Message -----
From: "Mikael Larsson" <mickeboy@h...>
To: "ASP+" <aspx@p...>
Sent: Friday, June 01, 2001 5:34 PM
Subject: [aspx] Dynamically change properties for webcontrols
> Hi...
>
>
> I have the following problem:
>
> I have a global variable
>
> String TableColor = "";
>
> and want to assign the value of TableColor to BackColor
>
> <ASP:DataGrid id="MyDataGrid" runat="server"
> Width="100%"
> BackColor="<%=TableColor%>
> BorderColor="black"
> ShowFooter="false"
> CellPadding="3"
> CellSpacing="0"
> Font-Name="Verdana"
> Font-Size="8pt"
> HeaderStyle-BackColor="#aaaadd"
> />
>
> But I canīt get it right. Is it possible? Can someone please help me?
>
> Best regards
>
> Mikael
Message #3 by "c2i - Richard Clark" <rc@c...> on Sat, 2 Jun 2001 14:09:48 +0200
|
|
It's not the answer to your question but try to don't use inline code with
ASP.net
In Page_Load event, write :
MydataGrid.Backcolor = CType(TableColor,Color)
or something like that
Richard Clark - rc@c...
______________________________________________
NOUVEAU : Liste de diffusion sur MS.NET
Inscription en envoyant un mail ā :
----------------------------------------------
dotnetfrance-subscribe@y...
----------------------------------------------
http://www.c2i.fr - Le portail francophone
Visual Basic,VB.NET,ASP, ASP.NET
+ de 517 aides disponibles (15/02)
______________________________________________
----- Original Message -----
From: "Mikael Larsson" <mickeboy@h...>
To: "ASP+" <aspx@p...>
Sent: Friday, June 01, 2001 5:34 PM
Subject: [aspx] Dynamically change properties for webcontrols
> Hi...
>
>
> I have the following problem:
>
> I have a global variable
>
> String TableColor = "";
>
> and want to assign the value of TableColor to BackColor
>
> <ASP:DataGrid id="MyDataGrid" runat="server"
> Width="100%"
> BackColor="<%=TableColor%>
> BorderColor="black"
> ShowFooter="false"
> CellPadding="3"
> CellSpacing="0"
> Font-Name="Verdana"
> Font-Size="8pt"
> HeaderStyle-BackColor="#aaaadd"
> />
>
> But I canīt get it right. Is it possible? Can someone please help me?
>
> Best regards
>
> Mikael
>
|
|
 |