我在完全绑定 aspx 文件中的通用列表时遇到问题。虽然它正确绑定到我的<p>
和<h>
标签,但不是我的 ImageButton。我在这里做错了什么。下面是我的代码
.aspx 文件
<%
int count = 1;
for (item = 0; item < mList.Count; AddItem())
{
if (count == 3)
{ %>
<div class="one_third_last">
<% count = 0;
}
else
{ %>
<div class="one_third">
<%}
count++;%>
<div class="modern_img_frame modern_four_col_large">
<div class="preload_four_col_large">
<div class="attachment-fadeIn">
<asp:ImageButton ID="ImageButton" runat="server" ImageUrl="~/images2/premium-website-template-2.jpg"
ToolTip="CSS Template" AlternateText="CSS Template" Width="190" Height="111"
CommandName="<%# mList[item].PaymentCode %>" CommandArgument="<%# mList[item].PaymentDescription %>"
OnCommand="ImageButton_Command" />
</div>
</div>
</div>
<!-- end modern_img_frame -->
<h6>
<%= mList[item].PaymentDescription%></h6>
<p>
<%= mList[item].PaymentDescription%></p>
</div>
<%
} %>
代码背后
protected List<Payments_Default> mList;
protected int item;
public String PaymentCode { get; set; }
public String PaymentDescription { get; set; }
public int PaymentNumber { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
mList = new Payments_Default().GetPaymentTypes();
this.DataBind();
}
protected void AddItem()
{
item++;
}
protected List<Payments_Default> GetPaymentTypes()
{
List<Payments_Default> mList = new List<Payments_Default>();
Payments_Default mObject = null;
SqlCommand command = GenericSqlDataAccess.CreateCommandOnline("Text");
command.CommandText = "SELECT bla bla bla";
DataTable table = new DataTable();
table = GenericSqlDataAccess.ExecuteReader(command);
foreach (DataRow row in table.Rows)
{
mObject = new Payments_Default();
mObject.PaymentCode = row["PayTypeCode"].ToString();
mObject.PaymentDescription = row["PayTypeDesc"].ToString();
mObject.PaymentNumber = table.Rows.Count;
mList.Add(mObject);
}
return mList;
}