gridview正确排列字符串数据

时间:2011-02-12 20:36:13

标签: asp.net gridview

1)是否可以将字符串排列在右边? 2)是否有可能在该字段的值为null时,在相应的gridview字段

中包含“ - ”

1 个答案:

答案 0 :(得分:0)

    protected void Page_Load(object sender, EventArgs e)
    {
        GridView1.Columns[2].ItemStyle.HorizontalAlign = HorizontalAlign.Right;
    }

    void GridView_RowDataBound(Object sender, GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //Due to the fact that DBnull value by default would be just empty string
            e.Row.Cells[1].Text = (string.IsNullOrEmpty(e.Row.Cells[1].Text))?"-":e.Row.Cells[1].Text;

        }

    }