从code定义Datalist中HeaderTemplate中在C#背后 [英] Define Datalist HeaderTemplate in c# from code behind
问题描述
我写以下code在ASPX,问题是,我需要创建从code相同的DataList在C#后面:
I wrote following code in aspx, and the problem is that i need to create same datalist from code behind in C#:
<asp:DataList ID="DataList1" runat="server">
<HeaderTemplate>
<tr>
<th style="background-color: Black;">
<div style="color: White; font-size: medium; padding: 0; margin: 0;">
TEST</div>
</th>
<th>
<div style="background-color: #ADAAB1; color: #E3E2E7; padding: 5px; font-size: x-small;">
date</div>
</th>
<th>
<div style="background-color: #ADAAB1; color: #E3E2E7; padding: 5px; font-size: x-small;">
Buy/Sell</div>
</th>
<th>
<div style="background-color: #ADAAB1; color: #E3E2E7; padding: 5px; font-size: x-small;">
Call/Put</div>
</th>
<th>
<div style="background-color: #ADAAB1; color: #E3E2E7; padding: 5px; font-size: x-small;">
name</div>
</th>
<th>
<div style="background-color: #ADAAB1; color: #E3E2E7; padding: 5px; font-size: x-small;">
amount</div>
</th>
<th>
<div style="background-color: #ADAAB1; color: #E3E2E7; padding: 5px; font-size: x-small;">
price1</div>
</th>
<th>
<div style="background-color: #ADAAB1; color: #E3E2E7; padding: 5px; font-size: x-small;">
price2</div>
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<div>
<tr>
<td>
<div style="background-color: #71B24C; color: White; height: 50px; text-align: center;">
<%# Eval("option")%></div>
</td>
<td>
<div style="background-color: #ADAAB1; color: White; height: 50px; padding-right: 5px;
font-size: medium; text-align: center;">
<%# Eval("date")%></div>
</td>
<td>
<div style="background-color: #D9D9D3; padding-right: 5px; height: 50px; font-size: medium;
text-align: center;">
<%# Eval("type")%></div>
</td>
<td>
<div style="background-color: #D9D9D3; padding-right: 5px; height: 50px; font-size: medium;
text-align: center;">
<%# Eval("action")%></div>
</td>
<td>
<div style="background-color: #D9D9D3; padding-right: 5px; height: 50px; font-size: medium;
text-align: center;">
<%# Eval("pos_name")%></div>
</td>
<td>
<div style="background-color: #D9D9D3; padding-right: 5px; height: 50px; font-size: medium;
text-align: center;">
<%# Eval("amount")%></div>
</td>
<td>
<div style="background-color: #D9D9D3; padding-right: 5px; height: 50px; font-size: medium;
text-align: center;">
<%# Eval("unitPrice")%></div>
</td>
<td>
<div style="background-color: #D9D9D3; padding-right: 5px; height: 50px; font-size: medium;
text-align: center;">
<%# Eval("total")%></div>
</td>
</tr>
</div>
</ItemTemplate>
</asp:DataList>
我的意思是code,我展示的作品完美地aspx页面。我在获得同样的效果(显示DataList控件),而是通过后面的code有趣。我的意思是在code code背后是这样的:= DataList控件DataList控件新();我的问题是,我不知道如何与HeaderTemplate中code内工作落后。
如果您可以提供例如code,这将是很好!
I mean that code that i demonstrating works perfectly in aspx page. I am interesting in getting same effect (display datalist) but through the code behind. I mean to code in code behind something like : DataList = new DataList(); My problem is, i dont know how to work with HeaderTemplate within code behind. If you can provide example code, it would be nice!
推荐答案
在code的HeaderTemplate中后面的类型必须是了Itemplate的。请参考这些文章的信息,创建一个模板。
The HeaderTemplate in code behind must be of type ITemplate. Please refer to these articles for information on creating a template.
的http:/ /msdn.microsoft.com/en-us/library/system.web.ui.itemplate(v=VS.85).aspx
<一个href=\"http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k(SYSTEM.WEB.UI.WEBCONTROLS.DATALIST.HEADERTEMPLATE);k(HEADERTEMPLATE);k(TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV4.0%22);k(DevLang-CSHARP)&rd=true\" rel=\"nofollow\">http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k(SYSTEM.WEB.UI.WEBCONTROLS.DATALIST.HEADERTEMPLATE);k(HEADERTEMPLATE);k(TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV4.0%22);k(DevLang-CSHARP)&rd=true
希望他们能有所帮助。
这篇关于从code定义Datalist中HeaderTemplate中在C#背后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!