Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
More grid woes
Message
De
07/07/2005 08:41:07
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
07/07/2005 08:01:51
Information générale
Forum:
ASP.NET
Catégorie:
WebForms
Titre:
Versions des environnements
Environment:
ASP.NET
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Divers
Thread ID:
01029008
Message ID:
01029882
Vues:
12
>>You made kind of calculated field:) However you could do that keeping the column as double. Something like:
>>
>>
>>BoundColumn bc = new BoundColumn();
>>bc.DataField = "Value";
>>bc.HeaderText="Price";
>>bc.ItemStyle.HorizontalAlign=HorizontalAlign.Right;
>>bc.DataFormatString="{0:C2}"; // Format parameter 0 as currency with 2 decimal places
>>myDataGrid.Columns.Add(bc);
>>
Cetin

>
>I had tried that before but I get error:
>
cannot convert from 'System.Web.UI.WebControls.BoundColumn' to 'System.Web.UI.WebControls.DataControlField'
>on the following line:
>
myDataGrid.Columns.Add(bc);
Strange I even couldn't find a reference to "...WebControls.DataControlField"
I just tried this and worked:
*Just put a web datagrid on a new asp.net page
//...
	public class WebForm1 : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.DataGrid DataGrid1;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				DataGrid1.DataSource = GetDataSet().Tables["Orders"].DefaultView;
				BoundColumn bc = new BoundColumn();
				bc.DataFormatString="{0:C2}";
				bc.DataField="freight";
				bc.HeaderText="Freight";
				bc.ItemStyle.HorizontalAlign=HorizontalAlign.Right;
				DataGrid1.Columns.Add(bc);
			}
			DataBind();	
		}
		protected DataSet GetDataSet()
		{
			DataSet ds = new DataSet("Orders");
			SqlConnection cn  = new SqlConnection("server=127.0.0.1;Integrated Security=SSPI;Initial Catalog=NorthWind");
			SqlDataAdapter da = new SqlDataAdapter("Select * from Orders", cn);
			da.Fill(ds, "Orders");
			return ds;
		}
//...
PS:Using VS2003.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform