日期:2014-05-17  浏览次数:20461 次

关于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);