2016-07-11 3 views
0

GridView에 추가하면 코드에서 보여지는 배경색이나 텍스트가 Cambial에 표시됩니다.모양 변경 TemplateField를 C#

어떻게하면됩니까?

<asp:TemplateField HeaderText="01"> 
     <EditItemTemplate> 
      <asp:DropDownList ID="falta1" runat="server" > </asp:DropDownList> 
     </EditItemTemplate> 
     <ItemTemplate> 
      <asp:Label ID="Label1" runat="server" Text='<%# Bind("c1") %>'></asp:Label> 
     </ItemTemplate> 
</asp:TemplateField> 
+0

어떤 요소의 배경을 변경 하시겠습니까? – weirdgyn

답변

3

오신 것을 환영합니다.

<asp:TemplateField HeaderText="Type" ControlStyle-BackColor="Black"> 

...에 대해 당신은 ControlStyle 같은 다른 속성에 대한 옵션의 목록을 볼 컨트롤 태그 내에서 스페이스 바를 칠 수있는 방법.

질문에 이미 시도한 것을 게시하면 더 나은 답변을 얻을 수 있습니다.

+0

안녕하십니까 코드 C# 및 사용되지 않은 이벤트 이후 –

1

코드 숨김에서 RowDataBound 이벤트에서 FindControl을 사용하여 레이블에 액세스 한 다음 레이블의 색, 텍스트를 변경해야합니다.

protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
    if(e.Row.RowType == DataControlRowType.DataRow) 
    { 
     Label oLabel = (Label)e.Row.FindControl("Label1"); 
     if(oLabel != null) 
     { 
      //oLabel.BackColor = System.Drawing.Color.Red;//See below for cambial 
      oLabel.BackColor = System.Drawing.ColorTranslator.FromHtml("#FFCC99"); 
      oLabel.Text = "MyText"; 
     } 
    } 
} 
+0

안녕하세요 단일보기 이벤트를 사용하지 않고 –

+0

감사합니다 ... 할 수 있습니다 .... –