自动生成的列,无法应用DataGrid1.Columns(i),MSDN中有说明,直接在<asp:....>中写!

解决方案 »

  1.   

    ms-help://MS.NETFrameworkSDKv1.1.CHS/cpref/html/frlrfSystemWebUIWebControlsDataGridClassColumnsTopic.htm
      

  2.   

    <asp:BoundColumn DataField="CurrencyValue" 
                     HeaderText="Price"
                     DataFormatString="{0:c}">               <ItemStyle HorizontalAlign="Right">
                   </ItemStyle>
    </asp:BoundColumn>
      

  3.   

    1。设置datagrid样式最好用“属性生成器”,自带的,不容易错
    2。在datagrid上右键
      

  4.   

    还有一种方法是在itemdatabound事件中设置:
    public void MyDataGrid_OnItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
    e.Item.Cells[5].HorizontalAlign=HorizontalAlign.Right;
      }