Unable to Set DataGrid Column Width in ASP.NET

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • VijaySofist
    New Member
    • Jun 2007
    • 107

    Unable to Set DataGrid Column Width in ASP.NET

    Hi All!

    I am using ASP.Net with Vb Coding in Windows XP Machine. I am Using a DataGrid and I am Passing a DataBase to this DataGrid. Data are get filled from the DataBase. Now I want to Set the First Column Width to Some pixels (Ex: 150 pixels).

    I am using the following code:

    Code:
    Datagrid1.Columns(0).ItemStyle.Width.Pixel(150)
    But it does n't works.

    Thanks in Advance

    With Regards
    Vijay. R
    Last edited by VijaySofist; Dec 28 '07, 05:18 AM. Reason: Left the OS
  • nateraaaa
    Recognized Expert Contributor
    • May 2007
    • 664

    #2
    What is the AutoGenerateCol umns property of your datagrid set to?

    If you want to control the width of your columns it should be set to false.

    Nathan

    Comment

    • VijaySofist
      New Member
      • Jun 2007
      • 107

      #3
      Originally posted by nateraaaa
      What is the AutoGenerateCol umns property of your datagrid set to?

      If you want to control the width of your columns it should be set to false.

      Nathan

      Hi!

      First of all Thanks for your Reply.

      My Datagrid's AutoGenerateCol umns property = True

      If I set it to False Then then DataBase Values are not been populated into it.
      What Should I do in this situation
      My Code is
      Code:
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
              sqlcon.ConnectionString = "server=2k6;database=orgsat;UID=sa;pwd=gopalan;"
              sqlcon.Open()
              sqlcmd.CommandText = "Select Date=convert(varchar(10),ndate,105),Topic=substring(Ntopic,1,15),UserId from satuserpost union select Date=convert(varchar(10),rdate,105),Topic=substring(rmessage,1,15),UserId=ruserid from SatPostreply"
              sqlcmd.CommandType = Data.CommandType.Text
              sqlcmd.Connection = sqlcon
              sdrdata = sqlcmd.ExecuteReader
              DataGrid1.DataSource = sdrdata
              DataGrid1.DataBind()
              DataGrid1.Columns(1).ItemStyle.Width.Pixel(1)
              sqlcon.Close()
          End Sub



      Thanks and Regards
      Vijay. R

      Comment

      Working...