Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 对齐左侧的Gridview列值_C#_Asp.net_Css - Fatal编程技术网

C# 对齐左侧的Gridview列值

C# 对齐左侧的Gridview列值,c#,asp.net,css,C#,Asp.net,Css,对齐左侧的列值我正在使用此代码 protected void GridView1_RowDataBound(object o, GridViewRowEventArgs e) { //Assumes the Price column is at index 4 if (e.Row.RowType == DataControlRowType.DataRow) e.Row.Cells[2].HorizontalAlign = HorizontalAlign.Right;

对齐左侧的列值我正在使用此代码

protected void GridView1_RowDataBound(object o, GridViewRowEventArgs e)
{
   //Assumes the Price column is at index 4
   if (e.Row.RowType == DataControlRowType.DataRow)
        e.Row.Cells[2].HorizontalAlign = HorizontalAlign.Right;
}
但我没有得到,因为我像这样控制着电网

 protected void GridView1_DataBound1(object sender, EventArgs e)
 {
    for (int rowIndex = grdtcwisetarget.Rows.Count - 2; rowIndex >= 0; rowIndex--)
    {
       GridViewRow gvRow = grdtcwisetarget.Rows[rowIndex];
       GridViewRow gvPreviousRow = grdtcwisetarget.Rows[rowIndex + 1];
       for (int cellCount = 0; cellCount < 2;cellCount++)
       {
           if (gvRow.Cells[cellCount].Text == gvPreviousRow.Cells[cellCount].Text)
           {
               if (gvPreviousRow.Cells[cellCount].RowSpan < 2)
               {
                  gvRow.Cells[cellCount].RowSpan = 2;
               }
               else
               {
                  gvRow.Cells[cellCount].RowSpan =
                  gvPreviousRow.Cells[cellCount].RowSpan + 1;
               }
             gvPreviousRow.Cells[cellCount].Visible = false;
           }
         }
       }
    }
  foreach (GridViewRow  row in GridView1.Rows)
        {
            foreach (TableCell cell in row.Cells)
            {
                cell.Attributes.CssStyle["text-align"] = "left";
            }
        }
受保护的void GridView1\u数据边界1(对象发送方,事件参数e)
{
对于(int rowIndex=grdtcwisetarget.Rows.Count-2;rowIndex>=0;rowIndex--)
{
GridViewRow gvRow=grdtcwisetarget.Rows[rowIndex];
GridViewRow gvPreviousRow=grdtcwisetarget.Rows[rowIndex+1];
对于(int-cellCount=0;cellCount<2;cellCount++)
{
if(gvRow.Cells[cellCount].Text==gvrevivousrow.Cells[cellCount].Text)
{
if(gvPreviousRow.Cells[cellCount].RowSpan<2)
{
gvRow.Cells[cellCount].RowSpan=2;
}
其他的
{
gvRow.Cells[cellCount].RowSpan=
gvPreviousRow.Cells[cellCount].RowSpan+1;
}
gvPreviousRow.Cells[cellCount].Visible=false;
}
}
}
}
试试这个

e.Row.Cells[2].HorizontalAlign = HorizontalAlign.Left;// Not Right 
并且必须使用RowDataBound事件。

请这样尝试

 protected void GridView1_DataBound1(object sender, EventArgs e)
 {
    for (int rowIndex = grdtcwisetarget.Rows.Count - 2; rowIndex >= 0; rowIndex--)
    {
       GridViewRow gvRow = grdtcwisetarget.Rows[rowIndex];
       GridViewRow gvPreviousRow = grdtcwisetarget.Rows[rowIndex + 1];
       for (int cellCount = 0; cellCount < 2;cellCount++)
       {
           if (gvRow.Cells[cellCount].Text == gvPreviousRow.Cells[cellCount].Text)
           {
               if (gvPreviousRow.Cells[cellCount].RowSpan < 2)
               {
                  gvRow.Cells[cellCount].RowSpan = 2;
               }
               else
               {
                  gvRow.Cells[cellCount].RowSpan =
                  gvPreviousRow.Cells[cellCount].RowSpan + 1;
               }
             gvPreviousRow.Cells[cellCount].Visible = false;
           }
         }
       }
    }
  foreach (GridViewRow  row in GridView1.Rows)
        {
            foreach (TableCell cell in row.Cells)
            {
                cell.Attributes.CssStyle["text-align"] = "left";
            }
        }
此外,请检查此属性
ItemStyle HorizontalAlign

<Columns>
  //any type of column here 
    ItemStyle-HorizontalAlign="Right" ItemStyle-Width="80" />
</Columns>

我尝试过这段代码也保护了void GridView1_RowDataBond(对象o,GridViewRowEventArgs e){//假设Price列位于索引4,如果(e.Row.RowType==DataControlRowType.DataRow)e.Row.Cells[2]。HorizontalAlign=HorizontalAlign.Right;}@REx和Ramesh,,,感谢您的响应,,,rex我知道了,,,但所有列都向左对齐,,,,但我只需要一列左侧,,,其他列的值是数字的,,,这是y,感谢您的响应,,,,rex我知道了,,,但所有列都向左对齐,,,,但我只需要一列左侧,,,,其他列的右值是数字的,,,这是y,只需要一列的ItemStyle HorizontalAlign=“正确”仅用于该列我正在动态绑定数据,但列定义是在定义网格的位置给出的,在aspx页面我正在动态绑定,,,因此我这里没有boundfield,,,那么我如何使用标记???