DataGrid Column widths not changing - help!!!

Discussion in 'ASP .Net Web Controls' started by Andre Ranieri, Sep 29, 2003.

  1. I forgot to ask, but are there any properties and methods
    that would allow me to customize the output formatting of
    the bound columns? For example, I'd like the date
    completed to show in short date format, the balance to
    show as a decimal/currency.

    Thanks,

    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();
    ..
    Andre Ranieri, Sep 29, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. wh1974
    Replies:
    1
    Views:
    1,556
    =?Utf-8?B?RmVybmFuZG8gSHVudGg=?=
    Jan 11, 2005
  2. =?Utf-8?B?RWxtZXI=?=

    Datagrid column widths in edit mode

    =?Utf-8?B?RWxtZXI=?=, Apr 8, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    2,413
    =?Utf-8?B?RWxtZXI=?=
    Apr 19, 2005
  3. =?Utf-8?B?QWxleCBNYWdoZW4=?=

    Forced Column Widths in a DataGrid?

    =?Utf-8?B?QWxleCBNYWdoZW4=?=, Jun 16, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    7,645
    Walter Wang [MSFT]
    Jun 20, 2006
  4. vpravin
    Replies:
    5
    Views:
    414
  5. Andre

    DataGrid Column widths not changing - help!!!

    Andre, Sep 29, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    111
    Andre
    Sep 29, 2003
Loading...

Share This Page