当前位置: 代码迷 >> ASP.NET >> 关于GridView绑定后事件RowDataBound 方法改如何写顺便解释一下
  详细解决方案

关于GridView绑定后事件RowDataBound 方法改如何写顺便解释一下

热度:1527   发布时间:2013-02-25 00:00:00.0
关于GridView绑定后事件RowDataBound 方法改怎么写顺便解释一下
GridView绑定后事件RowDataBound 先绑定里面有一个TypeId,在执行玩绑定后 我想把这个TypeID 修改为 另一个表中的TypeName
网页:
<asp:GridView ID="GridView1" runat="server" Width="860px" AutoGenerateColumns="False" onrowdatabound="GridView1_RowDataBound" >
  <asp:BoundField DataField="TypeId" HeaderText="所属类别"/>
</asp:GridView>

.CS:
  /// <summary>
  /// 在绑定后对行进行绑定
  /// </summary>
  /// <param name="sender"></param>
  /// <param name="e"></param>
  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{

int Id =Convert.ToInt32(e.Row.Cells[1]);
string Type = productTypebll.GetProductTypeById(Id).Type;
e.Row.Cells[1].Text = Type;

}

------解决方案--------------------------------------------------------
C# code
      if (e.Row.RowType == DataControlRowType.DataRow)      {          e.Row.Cells[0].Text = "a";      }
------解决方案--------------------------------------------------------
int Id =Convert.ToInt32(e.Row.Cells[1].Text);
  相关解决方案