A
Andre
I'm trying to programmatically create columns for a datagrid and set
their width. The "Services" field especially has a fairly long text
value, I'd like to make it wider than the default.
I've scoured the MSDN library and the newsgroups, and have tried
setting the Itemstyle.Width of the bound column as well as
dgRecentServices.Columns[1].ItemStyle.Width = Unit.Pixel(400);.
Would someone please point me in the right direction? I'm not sure
what I'm doing wrong.
Thanks,
Andre
private void dgFillRecent()
{
BoundColumn bc = new BoundColumn();
bc.HeaderText = "Invoice";
bc.DataField = "ServiceID";
bc.ItemStyle.Width = Unit.Pixel(500);
dgRecentServices.Columns.Add(bc);
bc = new BoundColumn();
bc.HeaderText = "Service";
bc.DataField = "Service";
dgRecentServices.Columns.Add(bc);
bc = new BoundColumn();
bc.HeaderText = "Status";
bc.DataField = "Status";
dgRecentServices.Columns.Add(bc);
bc = new BoundColumn();
bc.DataField = "DateCompleted";
bc.HeaderText = "Date ";
dgRecentServices.Columns.Add(bc);
bc = new BoundColumn();
bc.DataField = "AmountCompleted";
bc.HeaderText = "Amount";
dgRecentServices.Columns.Add(bc);
bc = new BoundColumn();
bc.DataField = "Balance";
bc.HeaderText = "Balance";
dgRecentServices.Columns.Add(bc);
dgRecentServices.Columns[1].ItemStyle.Width = Unit.Pixel(400);
}
private void RecentServices(String sAccountKey, SqlConnection cn)
{
DateTime datNow = DateTime.Now;
dgFillRecent();
string sSQL = "SELECT TOP 7 Service, Status, PreNotifyType, " +
"DateScheduled, ServiceID, DateCompleted, AmountCompleted, Balance
" +
"FROM dbo.tblMainServices " +
"WHERE (AccountKey = " + sAccountKey + ") AND (DateCompleted < '" +
datNow + "') " +
"ORDER BY DateCompleted DESC;";
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand(sSQL, cn);
DataSet ds = new DataSet();
da.Fill(ds, "LastServices");
DataTable LastServices;
LastServices = ds.Tables["LastServices]"];
string sService, sStatus, sPreNotifyType, sServiceID;
DateTime datDateScheduled, datDateCompleted;
decimal decSaleAmount, decBalance;
dgRecentServices.DataSource=ds.Tables["LastServices"];
DataView source = new DataView(ds.Tables[0]);
dgRecentServices.DataSource = source ;
dgRecentServices.DataBind();
their width. The "Services" field especially has a fairly long text
value, I'd like to make it wider than the default.
I've scoured the MSDN library and the newsgroups, and have tried
setting the Itemstyle.Width of the bound column as well as
dgRecentServices.Columns[1].ItemStyle.Width = Unit.Pixel(400);.
Would someone please point me in the right direction? I'm not sure
what I'm doing wrong.
Thanks,
Andre
private void dgFillRecent()
{
BoundColumn bc = new BoundColumn();
bc.HeaderText = "Invoice";
bc.DataField = "ServiceID";
bc.ItemStyle.Width = Unit.Pixel(500);
dgRecentServices.Columns.Add(bc);
bc = new BoundColumn();
bc.HeaderText = "Service";
bc.DataField = "Service";
dgRecentServices.Columns.Add(bc);
bc = new BoundColumn();
bc.HeaderText = "Status";
bc.DataField = "Status";
dgRecentServices.Columns.Add(bc);
bc = new BoundColumn();
bc.DataField = "DateCompleted";
bc.HeaderText = "Date ";
dgRecentServices.Columns.Add(bc);
bc = new BoundColumn();
bc.DataField = "AmountCompleted";
bc.HeaderText = "Amount";
dgRecentServices.Columns.Add(bc);
bc = new BoundColumn();
bc.DataField = "Balance";
bc.HeaderText = "Balance";
dgRecentServices.Columns.Add(bc);
dgRecentServices.Columns[1].ItemStyle.Width = Unit.Pixel(400);
}
private void RecentServices(String sAccountKey, SqlConnection cn)
{
DateTime datNow = DateTime.Now;
dgFillRecent();
string sSQL = "SELECT TOP 7 Service, Status, PreNotifyType, " +
"DateScheduled, ServiceID, DateCompleted, AmountCompleted, Balance
" +
"FROM dbo.tblMainServices " +
"WHERE (AccountKey = " + sAccountKey + ") AND (DateCompleted < '" +
datNow + "') " +
"ORDER BY DateCompleted DESC;";
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand(sSQL, cn);
DataSet ds = new DataSet();
da.Fill(ds, "LastServices");
DataTable LastServices;
LastServices = ds.Tables["LastServices]"];
string sService, sStatus, sPreNotifyType, sServiceID;
DateTime datDateScheduled, datDateCompleted;
decimal decSaleAmount, decBalance;
dgRecentServices.DataSource=ds.Tables["LastServices"];
DataView source = new DataView(ds.Tables[0]);
dgRecentServices.DataSource = source ;
dgRecentServices.DataBind();