2011-06-08 78 views

回答

5

讓該列模板列,並把標籤

<asp:TemplateField HeaderText="HeaderText"> 
<ItemTemplate> 
<asp:Label ID="lbl" runat="server" ></asp:Label> 
</ItemTemplate> 

,然後你在RowDataBound事件的GridView

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
if (e.Row.RowType == DataControlRowType.DataRow) 
{ 
    DataRow dr = ((DataRowView)e.Row.DataItem).Row; 
    if(dr["ColumnName"].ToString() == "1") 
    { 
     ((Label)e.Row.FindControl("lbl")).Text = "A"; 
    } 
    else if(dr["ColumnName"].ToString() == "2") 
    { 
     ((Label)e.Row.FindControl("lbl")).Text = "B"; 
    } 
    ................ 
     ................ 
    } 
} 
+0

Akhatar..Thanks dear..Its真正的偉大工程做... – 2011-06-08 10:00:39

+0

並不總是可以將DataRowView轉換爲DataRow – 2014-08-14 18:04:28