asp:templatecolumn demo (C#) : Template Column « Asp Control « ASP.Net






asp:templatecolumn demo (C#)

<%@Page Language="C#"%>
<html>
<body>

<asp:datagrid  id="dgrTest" runat="server"
               autogeneratecolumns="false"
               forecolor="#000000"
               backcolor="#ffffff"
               cellpadding="3"
               gridlines="none"
               width="50%"
               font-name="tahoma,arial,sans-serif"
               font-size="14px">
  <headerstyle forecolor="#ffffff"
               backcolor="#808080"
               font-name="tahoma,arial,sans-serif"
               font-size="12px"
               font-bold="true"
               wrap="false" />
  <itemstyle   font-name="tahoma,arial,sans-serif"
               font-size="10px" />
  <alternatingitemstyle font-name="tahoma,arial,sans-serif"
               font-size="16px"
               backcolor="#ffff00" />

  <columns>

   <asp:templatecolumn>
     <headertemplate>
       <font size="2">Key</font>
     </headertemplate>
     <itemtemplate>
       <font size="4">
         <%# DataBinder.Eval(Container.DataItem, "Key") %>
       </font>
     </itemtemplate>
   </asp:templatecolumn>

   <asp:templatecolumn>
     <headertemplate>
       <font size="2">Value</font>
     </headertemplate>
     <itemtemplate>
       <font size="1">
         $<%# DataBinder.Eval(Container.DataItem, "Value", "{0:f2}") %>
       </font>
     </itemtemplate>
   </asp:templatecolumn>

  </columns>

</asp:datagrid>

</body>
</html>

<script Language="C#" runat="server">

void Page_Load() {

   // create a HashTable of values to bind to
   Hashtable tabValues = new Hashtable(4);
   tabValues.Add("A", 49.56);
   tabValues.Add("B", 28.33);
   tabValues.Add("C", 55);
   tabValues.Add("D", 20.74);
   tabValues.Add("E", 41.1);

   // set the DataSource property of the control to the
   // hashtable and bind it to display the values
   dgrTest.DataSource = tabValues;
   dgrTest.DataBind();

}

</script>

           
       








Related examples in the same category