ASP.NET

Row 행 에서 글씨에만 색깔 바꾸기

Godffs 2010. 8. 27. 15:29
반응형
그리드뷰 안에 선언된...

<asp:TemplateField HeaderText="글씨" ControlStyle-CssClass="list">

     <ItemTemplate>

          <asp:Label ID="lblFont" runat="server"
               Text='<%# Eval("Font", "{0:yyyy-MM-dd}") %>' ForeColor="#000080"></asp:Label>

     </ItemTemplate>

</asp:TemplateField>

DB에 있는 값을 뿌리기 위해 Text='
<%# Eval("Font", "{0:yyyy-MM-dd}") %> 선언 날짜형 변환도 같이 함

 



 

protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs e)

{

    Label lblFont;

    lblFont= (Label)e.Row.FindControl("lblFont");
 if (e.Row.RowType == DataControlRowType.DataRow)

            {

              if (DataBinder.Eval(e.Row.DataItem, "fonts") != System.DBNull.Value)

                {

                    lblFont.ForeColor = System.Drawing.Color.Red;

                }

            }

        }
}
 끝~



만약 이전에 두개의 값을 하나의 컬럼에 넣으면서 색상을 변경 하고자 할때~!

protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs e)

        {

            Label lblFont;

            lblFont= (Label)e.Row.FindControl("lblFont");

 

            if (e.Row.RowType == DataControlRowType.DataRow)

            {

                ((Label)e.Row.FindControl("lblFont")).Text = DataBinder.Eval(e.Row.DataItem, "Font1").ToString() + DataBinder.Eval(e.Row.DataItem, "Font2").ToString();
                if (DataBinder.Eval(e.Row.DataItem, "fonts") != System.DBNull.Value)

                {

                    lblFont.ForeColor = System.Drawing.Color.Red;
                }  

            }

        }



링크 주소를 넣고 자 할 때~~


<asp:TemplateField HeaderText="글씨" ControlStyle-CssClass="list">

     <ItemTemplate>
            <a href='../링크 주소/파일명.aspx?넘길값=<%# Eval("font1") %>' style="text-decoration:none;">

          <asp:Label ID="lblFont" runat="server"
               Text='<%# Eval("Font", "{0:yyyy-MM-dd}") %>' ForeColor="#000080"></asp:Label>

     </ItemTemplate>

</asp:TemplateField>

반응형