DataGrid properties

  • Thread starter Thread starter Marty McDonald
  • Start date Start date
M

Marty McDonald

When setting certain datagrid properties with the IDE (as in the property
window), they don't seem to take effect. For instance, Font Name. So I
have to set these via code-behind at the cell level. Is this expected?
Shouldn't anything on the properties window render accordingly? Thanks
 
Hi Marty,



Thanks for posting in the community!
From your description, you found that the webform DataGrid' properties you
set in the property window in VS.NET IDE didn't work, yes?
If there is anything I misunderstood, please feel free to let me know.

Based on my experience, since the DataGrid will be rendered as a Html Table
element to the client, so all the properties we set in DataGrid's property
window will be set into the TAble's style attribute. For example, as for
the below DataGrid:
<asp:DataGrid id="dgBound" runat="server" AutoGenerateColumns="False"
ForeColor="Magenta" Font-Bold="True"
Font-Size="20pt" Font-Names="Bodoni MT Black" BackColor="#E0E0E0">
<Columns>
<asp:BoundColumn DataField="index" HeaderText="Index"></asp:BoundColumn>
<asp:BoundColumn DataField="name" HeaderText="Name"></asp:BoundColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update"
HeaderText="Operations" CancelText="Cancel"
EditText="Edit"></asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete" HeaderText="Delete" CommandName="Delete"
</asp:ButtonColumn>
</Columns>
</asp:DataGrid>

When the DataGrid is rendered to client html, all the properties set in the
IDE's property window will be output in the certain table's "style"
attribute, just as:
<table cellspacing="0" rules="all" border="1" id="dgBound"
style="color:Magenta;background-color:#E0E0E0;font-family:Bodoni MT
Black;font-size:20pt;font-weight:bold;border-collapse:collapse;">

As for your situation that the properties not work, I think it is likely
that the properties are overrided by the DataGrid's ItemStyle or cell
styles. Since if we specitfy the child element's style, the parent's style
won't work any more. Would you please have a check in your datagrid's html
source or the code to see whether there are any other style code in the
DataGrid's sub elements?

In addtion, here is a test page I used to test the DataGrid's property, you
may also have a test on it if you feel anything unclear, here is the page
source:
----------------------------aspx page----------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>DGrid</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="500" align="center">
<tr>
<td>
<asp:DataGrid id="dgBound" runat="server" AutoGenerateColumns="False"
ForeColor="Magenta" Font-Bold="True"
Font-Size="20pt" Font-Names="Bodoni MT Black" BackColor="#E0E0E0">
<Columns>
<asp:BoundColumn DataField="index"
HeaderText="Index"></asp:BoundColumn>
<asp:BoundColumn DataField="name"
HeaderText="Name"></asp:BoundColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update"
HeaderText="Operations" CancelText="Cancel"
EditText="Edit"></asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete" HeaderText="Delete"
CommandName="Delete"></asp:ButtonColumn>
</Columns>
</asp:DataGrid></td>
</tr>
</table>
</form>
</body>
</HTML>


------------------------page code behind---------------------
public class DGrid : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid dgMain;
protected System.Web.UI.WebControls.DataGrid dgBound;
System.Web.UI.WebControls.TemplateColumn col;

private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
LoadData();
BindGrid();
}
}

protected void LoadData()
{
DataTable tb = new DataTable();
tb.Columns.Add("index");
tb.Columns.Add("name");
tb.Columns.Add("description");

for(int i=0;i<15;i++)
{
int index = i+1;
DataRow newrow = tb.NewRow();

newrow["index"] = index.ToString();
newrow["name"] = "Name" + index.ToString();
newrow["description"] = "Description" + index.ToString();

tb.Rows.Add(newrow);
}


Session["TEMP_DATA"] = tb;

}

protected void BindGrid()
{
DataTable tb = (DataTable)Session["TEMP_DATA"];

dgBound.DataSource = tb;
dgBound.DataBind();
}


#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{

}
#endregion

}

----------------------------------------------------------------------------
---------

Please check out my suggestion. If you have any further questions or need
any assistance, please feel free to post here.



Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Hi Marty,


Have you had a chance to check out my suggestions in the last reply or have
you resolved this problem? If you need any further assistance, please feel
free to post here.




Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Back
Top