PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

Column Width in a Gridview

 
 
=?Utf-8?B?SGVsZW4gVHJpbQ==?=
Guest
Posts: n/a
 
      13th Feb 2007
How can I change the column width in a gridview filled with a dataset? I
can't get TableStyle to work. Has anyone any sample code, please?

Thanks,
Helen

PS. I am creating a web page in ASP.Net 2.0 using C#.

This is my code so far:

SqlConnection cn; // Connection to the SQL database
SqlDataAdapter da;
DataSet ds;

cn = new SqlConnection();
da=new SqlDataAdapter("Select * From Patient",cn);
ds = new DataSet();

OpenConnection(cn); // Connects to the database
da.Fill(ds,"PatientTable");
dgPatients.DataSource = ds.Tables["PatientTable"];
dgPatients.DataBind();
cn.Close();



 
Reply With Quote
 
 
 
 
marss
Guest
Posts: n/a
 
      13th Feb 2007

Helen Trim wrote:
> How can I change the column width in a gridview filled with a dataset? I
> can't get TableStyle to work. Has anyone any sample code, please?
>
> Thanks,
> Helen
>
> PS. I am creating a web page in ASP.Net 2.0 using C#.
>
> This is my code so far:
>
> SqlConnection cn; // Connection to the SQL database
> SqlDataAdapter da;
> DataSet ds;
>
> cn = new SqlConnection();
> da=new SqlDataAdapter("Select * From Patient",cn);
> ds = new DataSet();
>
> OpenConnection(cn); // Connects to the database
> da.Fill(ds,"PatientTable");
> dgPatients.DataSource = ds.Tables["PatientTable"];
> dgPatients.DataBind();


Hi,
Add event handler for the RowCreated event:

.... OnRowCreated="GridView1_RowCreated" ...

protected void GridView1_RowCreated(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
DataControlFieldCell cell =
(DataControlFieldCell)e.Row.Cells[i];
//here add custom logic of column width settings, for example:
//if (cell.ContainingField.HeaderText == "Id")
// e.Row.Cells[i].Width = new Unit("100px");
}
}
}


> cn.Close();


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamically Resize Gridview Width Property (NOT Column Width) Hartman_Ralph@Hotmail.com Microsoft ASP .NET 0 2nd Jun 2009 04:59 PM
gridview column width =?Utf-8?B?cm9kY2hhcg==?= Microsoft ASP .NET 2 19th Nov 2007 04:08 PM
To set Column Width for Gridview =?Utf-8?B?cmtibmFpcg==?= Microsoft ASP .NET 5 6th Nov 2007 03:42 AM
Column Width in a Gridview =?Utf-8?B?SGVsZW4gVHJpbQ==?= Microsoft VC .NET 1 12th Feb 2007 08:46 PM
Set the width of a gridView column Samuel Shulman Microsoft ASP .NET 2 3rd Nov 2006 11:42 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:45 AM.